Skip to main content
Inspiring
March 17, 2013
Answered

Load & Unload external SWFs in main.swf

  • March 17, 2013
  • 1 reply
  • 2117 views

Hello, please I have problem with my project. I'm glad for every help I can get.

so, my issue is this:

I have main.swf which defaultly loads menubar.swf, and footer.swf in menubar.swf are buttons: button1_btn, button2_btn, button3_btn.

Main.swf is listening if button 1, 2 or 3 is clicked. If so main.swf loads content1.swf, content2.swf or content3.swf

for example: user clicked button1_btn which addedChild of content1.swf that comes from left side to center of the stage, and if user going to click button2_btn I want the content which is loaded(in this example is it content1.swf), will  go away from the stage to right side and then content2.swf will come from left side to the center of the stage.

I'm sorry for my english.

All help will be very appreciated.

Thanks so much in advance.

This topic has been closed for replies.
Correct answer kglad

ok, now i have this:

// (in public class)

private var contentLoader:Loader = new Loader();

private var content1Loader:Loader = new Loader();  // sign up page

// (in constructor function)

var signUpRequest:URLRequest = new URLRequest("../swf/menubar.swf");

content1Loader.load(signUpRequest);

// (not in constructor, somewhere in my code)

// menuMc   because of addEventListener is linking to button in else SWF

menuMc.signUp1_btn.addEventListener(MouseEvent.CLICK, goContent);

private function goContent(e:MouseEvent):void

{

     if(contentLoader)

     {

          TweenLite.to(contentLoader, 1, {x:stage.stageWidth});

     }

     contentLoader = this("content" + e.currentTarget.name.substr(17, 1) + "Loader");

     addChild(contentLoader);

     contentLoader.x = -1250; // out of stage because of tween

     TweenLite.to(contentLoader, 1, {x:0, ease:Elastic.easeInOut});

}

and i don't understand this line:

contentLoader = this("content" + e.currentTarget.name.substr(17, 1) + "Loader");

// contentLoaders name is:  static word content + dynamic name of button(character number 17th, ?) + static word Loader

right?

so contentLoader will load content called    content1Loader  ??


you're still changing the names of your buttons.

when you finally decide on your button names, add them to an array and use:

var buttonA:Array = [the button that corresponds to content1Loader, the buttons that corresponds to content2Loader, etc];

var prevOnStageLoader:Loader;

for(var i:int=0;i<buttonA.length;i++){

buttonA.addEventListener(MouseEvent.CLICK, goContent);

}

function goContent(e:MouseEvent):void

{

if(prevOnStageLoader){

TweenLite.to(prevOnStageLoader,1,{x:stage.stageWidth});

}

prevOnStageLoader=Loader(this["content"+(1+buttonA.indexOf(e.currentTarget))+"Loader"]);

      addChild(prevOnStageLoader);

      prevOnStageLoader.x = -1250;

      TweenLite.to(prevOnStageLoader, 1, {x:0, ease:Elastic.easeInOut});

}

1 reply

kglad
Community Expert
Community Expert
March 17, 2013

what's the problem?

Inspiring
March 17, 2013

My problem is: I fully don't know how to make this.

Simply, clicking somebutton addschild of somecontent and if someone click on somebutton whatevercontentX go out and whatevercontentY comes here.

kglad
Community Expert
Community Expert
March 17, 2013

when a button is clicked:

1.  tween your loader (if it has a non-null content property) stage right.  when that completes

2.  move your loader stage-left

3. load your next swf

4. when loading is complete, tween your loader to stage center.