Skip to main content
Participant
September 1, 2011
Question

How do I load an external swf at a frame after ClickToGoToAndStopAtFrame?

  • September 1, 2011
  • 2 replies
  • 496 views

Hi, I'm quite new in working with AS3.

I am designing a site with a menupage with buttons.

Some of these buttons are linked to a frame that contains an external swf, which is a portfolio.

By pressing the buttons 'AQUAREL" and "OLIEVERF" you will go to another frame and the swf-portfolio shows up.

Now the problem is: sometimes it seems to work, sometimes it doesn't.

You can check out yourself at www.erwinvanzijl.nl

Is there a better whay of programming these functions?

Am I doing something wrong or is there a better way to do it?

This is the actionscript that I put on the second frame where the swf is to show up:

stop();

var Xpos_2:Number = 52;

var Ypos_2:Number = 59;

var swf_2:MovieClip;

var loader_2:Loader = new Loader();

var SWF_2:URLRequest = new URLRequest("aquaportfolio.swf");

loader.load(SWF_2);

loader.x = Xpos;

loader.y = Ypos;

addChild(loader);

btn_menu.addEventListener(MouseEvent.CLICK, unloadcontent_2);

function unloadcontent_2(event:MouseEvent):void {

removeChild(loader);

gotoAndStop("menu");

}

This topic has been closed for replies.

2 replies

September 1, 2011

In addition to what Ned mentioned, why do you have loader_2 defined, and then do everything with loader? Also, you might add some error listeners and see if you're getting an errror:

var loader_2:Loader = new Loader();

loader_2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

loader_2.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpHandler);

function ioErrorHandler(e:IOErrorEvent):void {
      trace(”ioErrorHandler", e);

}

function httpHandler(e:HTTPStatusEvent):void {

     trace("httpStatusHandler", e);

}

Tootsy151Author
Participant
September 1, 2011

Hi there dmennenoh,

Thanks for your response.

I added the _2 in the first lines because I used these lines before at the thist frame where the first swf is to be loaded.

And because the Flash program had a problem with these lines, I added the _2 and Flash stopped complaining about it.

I'm not really good at this and just want it to run smoothly.

So your saying that I should mention loader_2 through the entire code?

And what is the benefit of using an error listener? What does it do?

Ned Murphy
Legend
September 1, 2011

There doesn't appear to be anything wrong with the code, and I couldn't get anything to appear to act wrong visiting the site.  One thing you could probably do though is unload() the loader before you remove it.

Tootsy151Author
Participant
September 1, 2011

Hi Ned, Thans for your quick answer!

Euuh, but like I mentioned before: I know very little about AS3.

Can you show how to unload the loader within the existing code?

Ned Murphy
Legend
September 1, 2011

For the unloading it is a simple matter of...

function unloadcontent_2(event:MouseEvent):void {

   loader.unload();

   removeChild(loader);

   gotoAndStop("menu");

}

Follow what Dave has to say... he's far more experienced than I.  I was too hung up wondering what swf2 was all about to ntoice there were two loaders involved in the code.