Accessing variables in AS3 between 'movieclips'

This is puzzleing? And I feel that the answer is staring me in the face but I cannot see it!:crying:

I have finally started with AS3 and flip-'eck its a different animal that AS2

I have a swf called login.swf and in it have declared the variables var total:uint=0; and
loginState:Boolean=false

All my scripts for logging in sending/receiving variable from/to server scripts are all working!
(If anyone wants to see them/help on this let me know)

So… when a user supplies a correct password another swf (userLogged.swf) is loaded (note: in AS3 this process is seriously different than in AS2) swf dont seem to be loaded ‘into’ another movieclip anymore… and this leads me to the puzzle!

How do I access variables declared in the project.swf, from within the userLogged.swf!

the old AS2 way = trace (_root.loginState);

or trace (_root.project.loginState)!

I am stumped by this new approach of AS3 of loading in other swf files. The _root. options is no longer available in AS3 (that much I’ve descovered, some tuts say use root. but I cannot get that to work)

trace (root.loginState)
or

var userLoggedIn=root.loginState

gives me the error

1119: Access of possibly undefined property loginStatus through a reference with static type flash.display:DisplayObject.

when I try to publish the userLogged.swf

help!:expressionless:

thank
phpman


i laugh at aliens

the loader class is a display extends a display object so you can use it as movieclip or sprite with whatever it is loading.

say you have mainSWF loading subSWF, each has variables called foo set in their frames.

in mainSWF you’ll have:


var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete);
addChild(loader);
loader.load(new URLRequest("subSWF.swf"));

function handleComplete(event:Event):void{
    trace(foo+" says "+squareMc.foo);
    trace((loader.content as MovieClip).foo+" says "+(loader.content as MovieClip).circleMc.foo);
}

it will output all those variables.

you can find the src code here

Thanks, Bzouchir, that helps loads, I’ve managed to get that working, to some extent.

But I have decided, anyway, to go way back on the drawing board and start at a much more basic level that I first thought I’d need to.

I am going to get to grips with the baiscs of ActionScript 3.0 OOP before I attempt things to complex!

Cheers
manphp


i laugh at aliens