Jump to content
GreenSock

un4given

change button function depending on which swf is loaded

Recommended Posts

I have a pre loader that loads in a swf and in the preloader is a NAV bar and a forward and previous button.

 

Is there a way to change the function depending on which swf is loaded?

 

like: if SWF "page1" is loaded forward_btn = function.

 

I think this makes sense..

Link to comment
Share on other sites

Sure, just use conditional logic. Either re-point your event listeners when you load a new swf or use conditional logic inside your handler..

 

if (swfLoader.name == "page1") {
   //do stuff...
} else if (swfLoader.name == "page2") {
  //do stuff...
}

Link to comment
Share on other sites

I tried the codee ou have suggested but got the error:

 

Scene 1, Layer 'Layer 2', Frame 1, Line 14 1119: Access of possibly undefined property name through a reference with static type Class.

 

 

below is the code I have used

 

 

var page1loader:SWFLoader = new SWFLoader("page1.swf", {name:"pone", container:this});
var page2loader:SWFLoader = new SWFLoader("page2.swf", {name:"ptwo", container:this});


page1loader.load();


button.addEventListener(MouseEvent.CLICK, gogo);

function gogo(evt){
if (SWFLoader.name == "pone") {

   page1loader.unload();
page2loader.load();

} else if (SWFLoader.name == "ptwo") {

  page2loader.unload();
  page1loader.load();

}
}

Link to comment
Share on other sites

you need to tell each SWFLoader to have an eventHandler for onComplete, only when that event fires will you know which loader just loaded.

once you can detect that, you can set up a variable to store the name of the loader

 

 

 

http://www.greensock.com/as/docs/tween/ ... oader.html

 

 


import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

var page1loader:SWFLoader = new SWFLoader("page1.swf", {name:"pone", container:this, onComplete:completeHandler});
var page2loader:SWFLoader = new SWFLoader("page2.swf", {name:"ptwo", container:this, onComplete:completeHandler});

page1loader.load();





//variable to track recently loaded SWFLoader's name
var loadedSwf:String;

function completeHandler(event:LoaderEvent):void {
    trace(event.target.name + " is complete!");
    loadedSwf = event.target.name

}

 

 

 

then your button handler will be able to use the conditional logic necessary to move on

 

 

button.addEventListener(MouseEvent.CLICK, gogo);

function gogo(evt){
  if (loadedSwf == "pone") {

   page1loader.unload();
  page2loader.load();

} else if (loadedSwf == "ptwo") {

  page2loader.unload();
  page1loader.load();

}
}

Link to comment
Share on other sites

Carl!!

 

again you have saved ones bacon.

 

I really need to repay you somehow!

 

Damon

Link to comment
Share on other sites

glad it worked out for you.

 

c

Link to comment
Share on other sites

One more question.

 

is it possible to find out which SWF is loaded and unload it? rather then:

page3loader.unload();

 

is would be for my nav which consists of a lot of links

Link to comment
Share on other sites

you already know which loader just finished loading because you are storing its name in loadedSwf.

just do:

 

LoaderMax.getLoader(loadedSwf).unload();

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.
×