I am finding this solution everywhere:

Calling Parent Variables and Functions from a Loaded 
SWF<http://mattmaxwellas3.blogspot.com/2008/10/accessing-variables-and-functions-from.html>
Let's say I have one SWF (child.swf) that I want to load into another SWF 
(parent.swf), then I want to call a function that is in parent.swf from the 
child.swf. In AS2 you could just do _parent._parent as many times as needed to 
reach up the tree to get to the parent's top level. In AS3 you need to use this 
code below instead. Put it inside the child.swf. I have no idea what this line 
of code means, but is magic:

MovieClip(parent.parent).ParentFunction();

...then this sample code goes inside the parent.swf on its main timeline:

//this sample code loads the external SWF into the Parent SWF
var indexSwfRequest:URLRequest = new URLRequest("index.swf");
var indexSwfLoader:Loader = new Loader();
indexSwfLoader.load(indexSwfRequest);
addChild(indexSwfLoader);
//This is the parent function that can be called from the command that is 
inside the child.swf
function ParentFunction():void{
trace("It worked!");
}





But for some reason I can not get that to work... I get: Error #1009: Cannot 
access a property or method of a null object



As if my path is not right....

________________________________
From: Lehr, Theodore
Sent: Monday, June 07, 2010 8:12 AM
To: Flash Coders List
Subject: Passing Var value to loaded swf

I found this code:

<in the parent swf>
gameLoader.contentLoaderInfo.addEventListener(Event.INIT, onInit);

function onInit(e:Event) {
    MovieClip(gameLoader.content).userId = 1000000;
}

<In the loaded swf>

    public class Game extends MovieClip {
    public var userId:int = 0;
        function Game() {
            addEventListener(Event.ADDED_TO_STAGE,Init);
        }
        function Init(e:Event) {
testText.text = String(userId);
}



I am not seeing how I can add the swf to the stage ( 
MovieClip(gameLoader.content).userId = 1000000;)



How can I add it to the stage?



_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to