PDA

View Full Version : how to load an External SWF with code?



level4designs
June 29th, 2008, 02:57 PM
This is probably fairly easy, it was at least in AS2, but I have 2 FLA's, one is design.fla, the other is code.fla...

in the design FLA... I load in the code...



var maintimeline:MovieClip;
maintimeline = stage.getChildAt(0);
var url:String (http://www.kirupa.com/forum/String);
var loader:Loader;
url='codemodule.swf';
var request:URLRequest=new URLRequest(url);
loader=new Loader();
initListeners(loader.contentLoaderInfo);
loader.load(request);
function initListeners(dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener(Event.COMPLETE,complet ed);
trace("load complete");
}

function completed(event:Event):void
{
maintimeline.addChild(loader);
}

stop();


then in my code.swf, after it gets loaded, I want to initialize the design.fla



var URL:String (http://www.kirupa.com/forum/String) = "http://192.168.2.2/version5";
trace("initializing from code");
var maintimeline:MovieClip;
maintimeline = stage.getChildAt(0);
var initilalize:initialize = new initialize(maintimeline, URL);


problem is I don't think my code.swf, where I set the maintimeline, is accessing the proper stage? or at least my initialize function starts to throw a bunch of errors because maintimeline is not correct here?

say I have something in my initialize class that wants to change a textbox_txt on the stage of my design.fla?

I get this error when I run my design.fla and the code.swf is loading

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at codemodule_fla::MainTimeline/frame1()

pensamente
June 30th, 2008, 05:22 AM
i'm not sure if this is your problem, but try to put in first frame of your code fla something like this:
stop();

addEventListener(Event.ADDED_TO_STAGE, go);

function go(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,go);
this.gotoAndStop (2);
}


I've break it to different keyframes, this.gotoAndStop (2); but instead you could just initialize your class there, dunno, but give it a try.

level4designs
June 30th, 2008, 10:38 AM
Worked like a charm... that is all I needed, thank you...