Solved

Problem loading and external SWF with AS3

Posted on 2009-07-05
1
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

689 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