Jump to content
Search Community

Preloader and FlashVars

almogdesign test
Moderator Tag

Recommended Posts

Hi so,

I'm using a loadermax as a preloader its ease, simple and works great. However I need to pass string date to my main swf file and not the preloader what's the best solution for this, can laodermax pass date between swf files?

 

Here is my current code -

/* Create the swf loader */

_swfLoader = new SWFLoader("main.swf",{alpha:0,container:this,name:"mainSWF",x:0,y:0,estimatedBytes:3500,scaleMode:"none",crop:true,onProgress:progressHandler,onComplete:_completeHandler, onError:_errorHandler});

_swfLoader.load(true);

 

Thanks,

Almog

Link to comment
Share on other sites

You can certainly use the SWFLoader's rawContent to pass data.

 

function completeHandler(event:LoaderEvent):void {
   var mc:MovieClip = mySWFLoader.rawContent;
   mc.setCustomData(flashVar1, flashVar2); //you create the setCustomData() method in your main class
}

 

But it's probably cleaner to just access the stage's loaderInfo to get the parameters directly. Just make sure you wait until the child swf is added to the display list to run the code, otherwise "stage" will be null.

 

//in your child:
if (this.stage != null) {
   init(null);
} else {
   addEventListener(Event.ADDED_TO_STAGE, init);
}

function init(event:Event=null):void {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   var myVar1:String = this.stage.loaderInfo.parameters.myFlashVar;
}

Link to comment
Share on other sites

You can certainly use the SWFLoader's rawContent to pass data.

 

function completeHandler(event:LoaderEvent):void {
   var mc:MovieClip = mySWFLoader.rawContent;
   mc.setCustomData(flashVar1, flashVar2); //you create the setCustomData() method in your main class
}

 

But it's probably cleaner to just access the stage's loaderInfo to get the parameters directly. Just make sure you wait until the child swf is added to the display list to run the code, otherwise "stage" will be null.

 

//in your child:
if (this.stage != null) {
   init(null);
} else {
   addEventListener(Event.ADDED_TO_STAGE, init);
}

function init(event:Event=null):void {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   var myVar1:String = this.stage.loaderInfo.parameters.myFlashVar;
}

 

Im having the same problem. How can I send the vars to the SWF? I tried this:

 

// first try
queue.append( new SWFLoader("swf/" + game, {name:"activeGame", estimatedBytes:3000, container:this, x:0, autoPlay:true, requireWithRoot:this.root}) );

//second try
queue.append( new SWFLoader("swf/" + game, {name:"activeGame", estimatedBytes:3000, container:this, x:0, autoPlay:true, FlashVars:"Joe=test"}) );

 

 

How can I declare the vars into the child SWF?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...