Hi Susanne,
if you download the sample files of this thread, you'll see the code of main.fla .
You could create one array ( like my_buttons in the sample ) for each main button and populate the array with sub buttons.
The problem is this line:
It must be declared once. So it must be out of the function:Code:loader=new Loader();
I've re-uploaded the attachment.Code:var my_videos:Array=new Array("movies/one.swf","movies/two.swf","movies/three.swf","movies/four.swf","movies/five.swf"); var my_buttons:Array=new Array(button_1,button_2,button_3,button_4,button_5); var request:URLRequest; var loader:Loader=new Loader(); var holder_mc:MovieClip=new MovieClip(); addChild(holder_mc); for(var i:int=0;i < my_videos.length;i++) { my_buttons[i].id=i; my_buttons[i].mouseChildren=false; my_buttons[i].buttonMode=true; my_buttons[i].addEventListener(MouseEvent.MOUSE_DOWN,onButtonDown); } function onButtonDown(evt:MouseEvent):void { if(loader!=null) loader.unload(); request=new URLRequest(my_videos[evt.target.id]); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded); loader.load(request); } function onImageLoaded(evt:Event):void { if(holder_mc.numChildren>0) holder_mc.removeChildAt(0); var swf:MovieClip=evt.target.loader.content as MovieClip; holder_mc.addChild(swf); }
Hi Susanne,
if you download the sample files of this thread, you'll see the code of main.fla .
You could create one array ( like my_buttons in the sample ) for each main button and populate the array with sub buttons.
i just downloaded and
still the same error!
no i didnt do anything
for those who got error, here the fix
Hello There,
Really Appreciate your tutorials... its great to see people finding the time to help others :)
I just have a couple of questions... as I have been racking my head over this for a while.
(1) In this tutorial the buttons are set as movies... what do I do to your as3 to make a normal (non movie) button work?
(2) If I want to add a non swf movie page, i.e. Home page = swf movie, Contact = swf movie, news = normal page (not swf)? what needs to be added in action script land for this to work?
Thanks in advance and I really appreciate any help.
Take care,
Anthony
Hi pulse,
1. If you want use buttons, you have to embed them into a MovieClip because otherwise you can't add id property to button cos Button class is not dynamic.
2. Just do not add the "normal" button into the array. Interact with it as a stand alone button. So use navigateToURL:
Code:my_button.addEventListener(MouseEvent.MOUSE_DOWN,onButtonDown); function onButtonDown(evt:MouseEvent):void { var request:URLRequest=new URLRequest("http://flepstudio.org/"); navigateToURL(request,"_blank"); }
Thanks for the reply... its wonderful that your able to provide a wee bit of advice for a struggling novice like myself :)
I'm still having a bit of trouble implementing this into my site. I've tried using some as3 code I found a while ago (out of interest)... everything seems to work, except I can't remove the movie when I transition between pages.
If you get a change it would be great if you can check out the script and see what I'm doing wrong or not adding... ps I'm sorry if what I'm doing is a bit messy.
Just to note there is a preloader on frame 1, and swf's are being loaded into a movie container.
stop();
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/homepage.swf");
mcContainer.load(url);
button_1.addEventListener(MouseEvent.CLICK, goHome);
function goHome (e:MouseEvent):void
{
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/homepage.swf");
mcContainer.load(url);
}
button_2.addEventListener(MouseEvent.CLICK, goNews);
function goNews (e:MouseEvent):void
{
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/news.swf");
mcContainer.load(url);
}
button_3.addEventListener(MouseEvent.CLICK, goBio);
function goBio (e:MouseEvent):void
{
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/Bio.swf");
mcContainer.load(url);
}
button_4.addEventListener(MouseEvent.CLICK, goDiscography);
function goDiscography (e:MouseEvent):void
{
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/discography.swf");
mcContainer.load(url);
}
button_5.addEventListener(MouseEvent.CLICK, goMedia);
function goMedia (e:MouseEvent):void
{
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/media.swf");
mcContainer.load(url);
}
forum_btn.addEventListener(MouseEvent.CLICK,goForu m);
function goForum(e:MouseEvent)
{
var request:URLRequest = new URLRequest("http://pulsecreation.yuku.com/");
navigateToURL(request);
}
button_7.addEventListener(MouseEvent.CLICK, goContact);
function goContact (e:MouseEvent):void
{
var mcContainer:Loader = new Loader();
addChild(mcContainer);
var url:URLRequest = new URLRequest("swfs/contact.swf");
mcContainer.load(url);
}
Many Thanks,
Anthony
Thank you Flep for this nice and useful tutorial.
Will be nice to know if it is possible combine this solution with an intro and outro animation in the loaded movies (one, two, three, etc).
Something like this:
When I click in mc, will be nice to play the intro animation, and when click on another mc, play the outro of the loaded movie, and then load the new movie and play the intro.
This will be really nice, and I'm shure can be done only adding some lines of code. I have tested lots of things and I haven't achieved anything, as I'm a starter in AS3.
Any suggestiones for achieving this?
Thank you,
XOXO
I get the same error but only after pressing a button for a second time once the new swf has loaded. This happens with every button if I click it a second time.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::Loader/unload()
at main_fla::MainTimeline/onButtonDown()
So how would the code change for something like this? The "homepage.swf" will have to load into the "main.swf", then the buttons within homepage navigate to the other pages. Every tutorial I've seen always has these nav. buttons stay on the stage while the swf pages swap out, but I'd like to know how to treat something like this.
![]()
Bookmarks