View Full Version : loadMovie in as3?
youwh
05-17-2008, 10:03 PM
AS2 we have loadMovie that will replace everything on the stage. How could I do that in AS3? Currently my swf is loaded on top of the stage, so I can see it over lapping. How can I go to the individual swf?
var loadit = new Loader();
loadit.unload();
loadit.load(new URLRequest("Memory.swf"));
MovieClip(root).mainSite.addChild(loadit);
desighforce
05-18-2008, 12:02 AM
I too am making the transition to as3 and it is quite the learning experience. Anyway, here is what works for me:
I am loading an external swf into container_mc and masking.
If you want to load it directly to stage, then comment out container_mc.addChild(ldr); and uncomment //addChild(ldr);
import flash.display.*;
import flash.net.URLRequest;
var ldr:Loader = new Loader();
ldr.mask = mask_mc;
var url:String = "boxes.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
container_mc.addChild(ldr);
//addChild(ldr);
Hope it helps, good luck. :)
youwh
05-18-2008, 08:32 AM
var loadit = new Loader();
loadit.load(new URLRequest("Memory.swf"));
addChild(loadit);
Its overlapping on top of the stage. I think we should not use addChild here cause it will load the stuff to the stage?
rnuthman
02-22-2009, 12:39 AM
I am having this same problem.. I want to replace the entire contents with another swf which was easily done in AS2 like so:
loadMovie( "whatever.swf", "_level0");
Can anyone help with this? I'm having the exact same problem migrating from 2 to 3. I have a simple swf with two buttons on the stage and I want each one to load a different swf and display it in a contentClip movieclip. But when I click on a second button I get this message:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::Loader/_load()
at flash.display::Loader/load()
at buttons_fla::MainTimeline/butt1Click()
Here is my code:
var home:MovieClip = this;
var ldr:Loader = new Loader();
function butt1Click(evt:MouseEvent):void{
ldr.load(new URLRequest("content1.swf"));
ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded, false, 0, true);
}
function butt2Click(evt:MouseEvent):void{
ldr.load(new URLRequest("content2.swf"));
ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded, false, 0, true);
}
function loaded(evt:Event):void {
contentClip.addChild(evt.target.content);
}
home.butt1.addEventListener(MouseEvent.MOUSE_UP, butt1Click);
home.butt2.addEventListener(MouseEvent.MOUSE_UP, butt2Click);
I've tried other things like putting var ldr:Loader = new Loader(); on the click events but that just loads the content on top of each other rather than replacing it.
I've sorted it out I think, there's probably a better way but this seems to be working.
var home:MovieClip = this;
function butt1Click(evt:MouseEvent):void {
var ldr:Loader = new Loader();
ldr.load(new URLRequest("content1.swf"));
ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
}
function butt2Click(evt:MouseEvent):void {
var ldr:Loader = new Loader();
ldr.load(new URLRequest("content2.swf"));
ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
}
function loaded(evt: Event):void {
if(contentClip.numChildren > 0){
contentClip.removeChildAt(0);
}
contentClip.addChild(evt.target.content);
}
home.butt1.addEventListener(MouseEvent.MOUSE_UP, butt1Click);
home.butt2.addEventListener(MouseEvent.MOUSE_UP, butt2Click);
Basically in the loaded function I check to see if there are any children in the content clip, if there are I remove them and then add the new child.
soniayayo
05-22-2011, 05:15 AM
I too am making the transition to as3 and it is quite the learning experience. Anyway, here is what works for me:
I am loading an external swf into container_mc and masking.
If you want to load it directly to stage, then comment out container_mc.addChild(ldr); and uncomment //addChild(ldr);
import flash.display.*;
import flash.net.URLRequest;
var ldr:Loader = new Loader();
ldr.mask = mask_mc;
var url:String = "boxes.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
container_mc.addChild(ldr);
//addChild(ldr);
Hope it helps, good luck. :)
How can I use this same code but to specify (gotoAndStop) a label within that loaded movie?
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.