We help IT Professionals succeed at work.

Problem loading external swf file Actionscript 3.0

b_yellow
b_yellow asked
on
3,434 Views
Last Modified: 2013-11-11
Hello,

I am dynamically loading my entire flash website as an external swf file ("bymain.swf").

The problem is that once the preloader finishes, the swf file has already played half way through the animation.

How do I get my swf file to play from Frame 1 after my preloader indicates it has loaded 100%.

I have attached the code that is used to dynamically load the swf.

Any help would be much appreciated! Let me know if you need my flash file to investigate further.

Thanks!
var myRequest:URLRequest = new URLRequest("bymain.swf");
var myLoader:Loader = new Loader();
 
myLoader.load(myRequest);
 
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent);
 
var myPreloader:Preloader = new Preloader();
 
function showPreloader(event:Event):void {
	addChild(myPreloader);
	myPreloader.x = stage.stageWidth/2;
	myPreloader.y = stage.stageHeight/2;
}
 
function showProgress(event:ProgressEvent):void {
	var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
	myPreloader.loading_txt.text = "" + Math.round(percentLoaded * 100) + "%";
	myPreloader.bar_mc.height = 100 * percentLoaded;
}
 
function showContent(event:Event):void {
	removeChild(myPreloader);
	addChild(myLoader);
}

Open in new window

Comment
Watch Question

Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi,

Thanks for your response! I'm sorry but I'm quite inexperienced at Flash!

I already have a stop action on Frame 1 of the external swf file with all of my content.

Should I move everything to Frame 2 and leave the stop action on Frame 1?

I have tried doing this, with putting a play() action within the main file (see attached), but with still no luck. The movie now loads and just stops on Frame 1.

I'm not sure I am putting the play action in correctly?

Thanks again!
var myRequest:URLRequest = new URLRequest("bymain2.swf");
var myLoader:Loader = new Loader();
 
myLoader.load(myRequest);
 
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent);
myLoader.contentLoaderInfo.addEventListener(Event.ENTER_FRAME, onComplete);
 
var myPreloader:Preloader = new Preloader();
 
function showPreloader(event:Event):void {
	addChild(myPreloader);
	myPreloader.x = stage.stageWidth/2;
	myPreloader.y = stage.stageHeight/2;
}
 
function showProgress(event:ProgressEvent):void {
	var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
	myPreloader.loading_txt.text = "" + Math.round(percentLoaded * 100) + "%";
	myPreloader.bar_mc.height = 100 * percentLoaded;
}
 
function showContent(event:Event):void {
	removeChild(myPreloader);
	addChild(myLoader);
}
 
function onComplete(e:Event):void {
var movie: * = myLoader.content;
movie.play();
}

Open in new window

Author

Commented:
Problem Solved! Thanks for your help. Ignore my last post!


Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.