Load External SWF through ComboBox AS3 - actionscript-3

I am trying to create a ComboBox that loads and unloads an external SWF onto stage using ActionScript 3.0 using Flash CS5.
Currently there are 2 list items in the combo box: Home and About.
Upon selecting Home or About option from ComboBox it displays both Home and About SWF at once when selected.
I only want 1 SWF to be displayed only when selected, not all.
menuList.addItem({label:"Choose"});
menuList.addItem({label:"Home",path:"home_load.swf"});
menuList.addItem({label:"About",path:"about.swf"});
menuList.addEventListener(Event.CHANGE, Home);
menuList.addEventListener(Event.CHANGE, About);
var loader:Loader = new Loader();
loader.unloadAndStop();
function Home(e:Event):void
{
if (e.currentTarget.selectedItem.path)
{
var loader:Loader = new Loader();
//loader.unloadAndStop();
loader.load(new URLRequest("home_load.swf"));
addChild(loader);
//loader.unloadAndStop();
loader.x = 0;
loader.y = 190;
}
}
function About(e:Event):void
{
if (e.currentTarget.selectedItem.path)
{
//loader.unloadAndStop();
var loader:Loader = new Loader();
loader.load(new URLRequest("about.swf"));
addChild(loader);
//loader.unloadAndStop();
loader.x = 0;
loader.y = 190;
}
}

You may have to do addChild after the swf file has completed loading.
//These listeners detect when the file has finished loading, and if the
//correct file is loaded.
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
swfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
//The load method then loads the SWF file into the loader object.
swfLoader.load(my_url);
//This function adds the external SWF to the stage.
function finishLoading(loadEvent:Event) {
addChild(loadEvent.currentTarget.content);
}
//This function displays a message if the file is not found.
function errorHandler(errorEvent:Event):void {
trace("file missing");
}

Related

ActionScript 3.0 can't load SWF file

I have a problem about loading a SWF file(the SWF with a Main.as)
Here is my code:
bt1.addEventListener(MouseEvent.CLICK, f1);
var myloader:Loader = new Loader();
var myURL:URLRequest = new URLRequest("test.swf");
myloader.load(myURL);
function f1(Event:MouseEvent):void
{
addChild(myloader);
myloader.x=100;
myloader.y=200;
myloader.width =200;
myloader.height =60;
}
When I clicked load button, I can hear the sounds(test.swf), but I cant see anything.
Did you try with stage.addChild(myloader);?

Flash AS3 load and replace movie

I have a loader mc...an animation that loops - when you click a button I want a new movie to load on top and replace the loader mc
Here is my current code:
btn_load.addEventListener(MouseEvent.CLICK, btn_load_press);
function btn_load_press(e:MouseEvent)
{
var reloadRequest:URLRequest = new URLRequest("new-movie.swf");
var loader:Loader = new Loader();
loader.load(reloadRequest);
addChild(loader);
}
But this puts it on top on my loader...effectively meaning the loader is still running in the background.
This is really simple in AS2 - and I'm not sure if it's even possible in AS3
To do this we'll need to add a listener for your loader.contentLoaderInfos complete event, then remove your animation once everything has finished loading.
btn_load.addEventListener(MouseEvent.CLICK, btn_load_press);
function btn_load_press(e:MouseEvent)
{
var reloadRequest:URLRequest = new URLRequest("new-movie.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loader_complete);
loader.load(reloadRequest);
addChild(loader);
}
function loader_complete(e:Event)
{
e.target.removeEventListener(Event.COMPLETE,loader_complete);
removeChild(loader_mc);
}

How to load new swf on mouseclick event of movieclip in as3?

I want to create a flip effect button, on click event of which a external swf should be opened removing all the contents of current swf.
I have created both components, a button and also a movieclip.
Neither of its load ( new URLRequest()) code working.
Below is the complete code I am using. Where btn2 is class name of my movie clip
and 2.swf is external swf I want to load.
stop();
var bc2:btn2 = new btn2();
bc2.buttonMode = true;
bc1.addEventListener(MouseEvent.CLICK, mouseClick);
var loader = new Loader();
function mouseClick(event:MouseEvent): void {
loader.unload();
loader.load(new URLRequest("2.swf"));
addChild(loader);
}
First btn2 instance what you are instantiating needs to be added for it to be visible.
Secondly you are trying to load the swf even before its loaded.
I have modified the code
stop();
var bc2:btn2 = new btn2();
bc2.buttonMode = true;
this.addChild(bc2);
bc2.addEventListener(MouseEvent.CLICK, mouseClick);
var loader = new Loader();
function mouseClick(event:MouseEvent): void {
loader.unload();
loader.load(new URLRequest("2.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
}
function completeHandler(event:Event):void{
this.addChild(loader);
}
This should work...

as3 play movieclip once

I would be very thankful if you help me with this problem.
I´m trying to play in my application for ipad one MovieClip once. i tried to do stopping in this way, but the movie dont stop
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.load(swfFile);
movieClip = new MovieClip();
movieClip.addChild(loader);
movieClip.addFrameScript(movieClip.totalFrames - 1, callbackFunc);
movieClip.play();
private function callbackFunc():void
{
movieClip.stop();
}
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFileLoaded);
loader.load(swfFile);
//I assume you have declared 'movieClip'?
//if not do:
//var movieClip:MovieClip;
private function onFileLoaded(e:Event):void
{
movieClip = loader.content;
addChild(movieClip);
movieClip.play();
addEventListener(Event.ENTER_FRAME, onEnter, true, 0, false);
}
private function onEnter(e:Event):void
{
if (movieClip.currentFrame == movieClip.totalFrames)
{
movieClip.stop();
removeEventListener(Event.ENTER_FRAME, onEnter, true, 0, false);
//do other stuff
}
}
This should do what you need.
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.load(swfFile);
private function callbackFunc():void
{
movieClip.stop();
}
function onCompleteHandler(loadEvent:Event)
{
movieClip = MovieClip(loadEvent.currentTarget.content);
addChild(movieClip);
movieClip.addFrameScript(movieClip.totalFrames - 1, callbackFunc);
movieClip.play();
}
Your code will not work because it's not the movieClip that is played, it's the external SWF that you load into it that will play it's keyframes. The created movieClip only has 1 keyframe, and on that 1 keyframe the external SWf is placed. You should add the stop() function into the external SWF. If you do this correct the external SWF plays once, and is then stopped.
You can also wrap the external SWF into a new MovieClip and put the code you already have onto it...
Or If you want full control, you can adapt the external SWF code so that this dispatches an event when the last frame is played. Provide a custom stop / replay function on the SWF which you can then call from the parent SWF.
Good luck!

Instantiate Document Class in as3

hi need to instantiate document class in as3. I have a main movie which will load load.swf. The document class of load.swf is LoadedMovie. i use this code :
public function Main()
{
var url:URLRequest = new URLRequest("load.swf");
loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
loader.load(url);
}
function finishLoading(e:Event)
{
var sn:LoadedMovie=new LoadedMovie();
addChild(sn);
}
it's added the movieclip and but my framescripts were not working. i have stop at last frame.
Is it any other way to do this.
The Loader will contain an instance of your loaded swf's document class once it's loaded. Simply addChild the loader and you're in business.
var url:URLRequest = new URLRequest("load.swf");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
loader.load(url);
addChild(loader);
Instanciating from a loaded swf is slightly more complicated, you have to deal with application domains and such.