Solved

Problem loading and external SWF with AS3

Posted on 2009-07-05
1
311 Views
Last Modified: 2013-11-11
Hi,

I have a button that jumps the timeline to frame 25 in my movie. On that frame I have the code below, which loads an external SWF. Problem is, it keeps loading the SWF over, and over. I'm new to AS3, and I'm pretty sure I need an if statement that says if the SWF is loaded, then delete the 'enter frame' function, but I can't seem to figure out how to write that.

Any help would be greatly appreciated!

Thanks!
addEventListener(Event.ENTER_FRAME, myFunction);

function myFunction(event:Event){

var load_mc = new Loader();

addChild(load_mc);

load_mc.load(new URLRequest("myMovie.swf"));

}

Open in new window

0
Comment
Question by:Coobakai
1 Comment
 
LVL 2

Accepted Solution

by:
Iklu earned 500 total points
ID: 24781363
I've included two examples of code because I don't think you really need to ENTER_FRAME event listener.
//With ENTER_FRAME

addEventListener(Event.ENTER_FRAME, myFunction);
 

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_Complete);

var load_mc:MovieClip;
 

function myFunction(e:Event):void

{

	loader.load(new URLRequest("myMovie"));

}

function loader_Complete(e:Event):void

{

	removeEventListener(Event.ENTER_FRAME, myFunction);

	loader.removeEventListener(Event.COMPLETE, loader_Complete);

	load_mc = loader.content as MovieClip;

	addChild(load_mc);

}
 

//Without ENTER_FRAME

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_Complete);

var load_mc:MovieClip;

loader.load(new URLRequest("myMovie"));
 

function loader_Complete(e:Event):void

{

	loader.removeEventListener(Event.COMPLETE, loader_Complete);

	load_mc = loader.content as MovieClip;

	addChild(load_mc);

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now