header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
sanjay
Points:0
Posts:0

9/7/2011 9:33:28 AM

Title: DispatchEvent not working


I have parent movieclip. It loads a child movieclip. If one tries to play just the child movieclip alone(without loading in parent movieclip), it is supposed to stop at frame 2, but if someone tries to load it from parent movieclip, it is supposed to play animations located on frame 3. When loading is complete, the child movieclip dispatches a custom event "showPL" and the parent movieclip is supposed to play animations on frame 3 by using code: MovieClip(myloader.content).gotoAndStop(3);. The problem I am facing is that it stops at frame 2, it does not play animations on frame 3. Thanks in advance, any help would be welcomed.





CODE ON PARENT MOVIECLIP


var myloader:Loader = new Loader();

part8_btn.addEventListener(MouseEvent.CLICK, loadF8);
function loadF8(e:MouseEvent):void{
	SoundMixer.stopAll();
myloader.load(new URLRequest("part8.swf"));
stage.addChild(myloader);
	myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
	
function swfLoaded(event:Event):void {
	myloader.content.addEventListener("showPL", showPL_handler);

}
function showPL_handler(event:Event):void {
    MovieClip(myloader.content).gotoAndStop(3);
	
	
	}

}


myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded);

function movieLoaded(event:Event):void { 
myloader.x=0; 
myloader.y=0; 
myloader.scaleX=1; 
myloader.scaleY=1; 
stage.addChild(myloader); 
} 

//CODE ON CHILD MOVIECLIP

addEventListener(Event.ENTER_FRAME, loaderF);

function loaderF(e:Event):void{
	var toLoad:Number = loaderInfo.bytesTotal;
	var loaded:Number = loaderInfo.bytesLoaded;
	var total:Number = loaded/toLoad;
	if(loaded == toLoad){
		
		removeEventListener(Event.ENTER_FRAME, loaderF);
		dispatchEvent(new Event("showPL"));
		gotoAndStop(2);
		
	}else{
		
		preloader_mc.preloaderFill_mc.scaleX = total;
		preloader_mc.percent_txt.text = Math.floor(total*100) + "%";
		preloader_mc.ofBytes_txt.text = loaded + "bytes";
		preloader_mc.totalBytes_txt.text = toLoad + "bytes";
	}
}





1
Derek
Points: 0
Posts:0
9/9/2011 10:46:51 PM



I had faced a similar issue long time back. The solution I did was to add a small time delay to move it to frame3. It seems that the when we try to move playhead to some frame, the movie is not initialized properly, its just loaded. So it does not behave in a proper way.

I called the "gotoAndStop(3)" after 500 ms time delay in complete event. So it seems to be enough time to allow loaded swf to initialize. I hope it works for you, let me know


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 1+14+3 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions