Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Loading external SWF's into an SWF Loader as3 style?

New Here ,
Nov 13, 2011 Nov 13, 2011

Hi,

I've recently made the switch from as2 to as3 and am still struggling to get my head around one aspect in particular. I've managed to load one external swf into a blank file via the script

import LoadDisplayObject;

var loader:LoadDisplayObject = new LoadDisplayObject("button_01.swf", true);

  1. loader.addEventListener("displayObjectLoaded", onComplete, false, 0, true);

addChild(loader);

function onComplete(evt:Event):void {

     trace("loaded complete received");

     loader.scaleX = loader.scaleY = .75;

}

.....however I'm struggling with the script to make a swfs load into a space when one of my 3 buttons is clicked....

My page currently has three buttons (button_01, button_02 and button_03) and in a local folder three separate swfs with the same names which I wish to load in, when the appropriate button is pressed. 

I have managed to get them to load in using a tutorial...however they load over the top of each over...far from ideal. From research on the internet I've found a range of different script...but I just can’t find anywhere I can find script to make this work..hence why I have turned to here.

Any help much appreciated...thanks in advance.

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Nov 14, 2011 Nov 14, 2011

just call butt1Click(null);

Translate
Community Expert ,
Nov 13, 2011 Nov 13, 2011

you must be using different loaders to load more than one swf at the same time.  assign them different x,y properties so they don't overlap:

loader.x=whatever;

loader.y=whatever;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 13, 2011 Nov 13, 2011

Your loader holds the loaded swf. By adding it as a child - addChild(loader) - you place it on the stage at the highest level possible. You could manage depths of added children by calling addChildAt(loader, whateverLevelIndex), but you can never addChild under the objects that are already on the stage in layers, added in Flash Professional IDE. You can position and size loaded content ofcourse, move it away from your buttons (loader.x, loader.y, loader.width, loader.height).

If your loaded content is and should be bigger and thus under the buttons, you should create empty movie clip and position it under the buttons at position [0, 0] and call it let's say myLoaderHolder.Then modify script:

myLoaderHolder.addChild(loader);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 13, 2011 Nov 13, 2011

Thanks a lot for the replys...I"ll give it ago this week and let you know how it goes.

Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 13, 2011 Nov 13, 2011

replies*

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2011 Nov 13, 2011

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 14, 2011 Nov 14, 2011

Hi,

Just throught I would let you know that I've manged to get this to work this morning. Changed the script slightly and used a different method of:

var home:MovieClip = this;


function butt1Click(evt:MouseEvent):void {
    var ldr:Loader = new Loader();
    ldr.load(new URLRequest("button_01.swf"));
    ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
}

function butt2Click(evt:MouseEvent):void {
    var ldr:Loader = new Loader();
    ldr.load(new URLRequest("button_02.swf"));
    ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
}

function butt3Click(evt:MouseEvent):void {
    var ldr:Loader = new Loader();
    ldr.load(new URLRequest("button_03.swf"));
    ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
}


function loaded(evt: Event):void {
    if(contentClip.numChildren > 0){
        contentClip.removeChildAt(0);
    }
    contentClip.addChild(evt.target.content);
}

button_01.addEventListener(MouseEvent.MOUSE_UP, butt1Click);
button_02.addEventListener(MouseEvent.MOUSE_UP, butt2Click);
button_03.addEventListener(MouseEvent.MOUSE_UP, butt3Click);

seems to work well. Only small question is if I want one page to load automatically upon opening...how do I alter the script to do this??? Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 14, 2011 Nov 14, 2011

just call butt1Click(null);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 14, 2011 Nov 14, 2011

Brilliant. Thankyou

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 14, 2011 Nov 14, 2011
LATEST

You're wellcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines