A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: The weirdest Flash bug ever (seriously, don't know what to put here)

  1. #1
    Member
    Join Date
    Jul 2009
    Location
    Florianópolis
    Posts
    81

    unable to assign Listeners to MCs (except if done at the moment of instantiation)

    Hello folks, I've come to a really strange bug in Flash:

    There is a swf called Nav.swf which contains on its stage a movieclip "som" which has its own class Som.as.

    There's an animation on Nav.swf, and when it ends it will call the method StartPlayer() on Som.as.

    If I run setupButtons() in the init() function, it works fine, I am able to click the button "btPlayPause" and it will trace what's in the function clickPlayPause();

    THE PROBLEM: If I leave it as it is on the example below (the setupButtons() function is only called by the startPlayer() method, which is called from Nav.swf a while later after Som is instantiated) it will trace what's in both functions startPlayer() and setupButtons() BUT the button "btPlayPause" won't work! It dosn't get the buttonMode property set to true (cursor does not change to the little hand) and when I click on it it does not run clickPlayPause(), it doesn't trace anything!

    The same happens if I call directly the setupButtons() function from the nav.swf. It will trace what's in setupButtons() but the movieclip won't listen to the MouseEvent.

    I cleaned up the code only to show what matters:

    Code:
    package br.com.dialetto.nav 
    {
    	import flash.display.*;
    	import flash.events.*;
    	
    	public class Som extends MovieClip {
    
    		public function Som() {
    			stage? init() : addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    		}
    		
    		private function setupButtons():void
    		{
    			trace ("Som/setupButtons");
    			
    			buttons.btPlayPause.addEventListener(MouseEvent.CLICK, clickPlayPause);
    			buttons.btPlayPause.buttonMode = true;
    		}
    		
    		//---------------------------------------
    		// EVENT HANDLERS
    		//---------------------------------------
    
    		private function onAddedToStage(e:Event):void
    		{
    			init();
    			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    		}
    
    		private function clickPlayPause(e:MouseEvent):void{
    			trace ("clickPlayPause");
    		}
    		
    		//---------------------------------------
    		// PUBLIC METHODS
    		//---------------------------------------
    	
    		public function init():void {
    			//setupButtons();
    		}
    			
    		public function startPlayer():void
    		{
    			trace ("Som/startPlayer");
    			
    			setupButtons();
    		}
    	}
    }
    Why does that happens??

    Thanks in advance!
    Last edited by ziriguidum; 08-09-2010 at 01:05 PM. Reason: make things clearer and write a decent title

  2. #2
    Member
    Join Date
    Jul 2009
    Location
    Florianópolis
    Posts
    81
    I've found the solution .

    It was actually a stupid mistake (i was talking to another object of the Som class that was unnecessairly instantiated)
    Mainly due to having two people writing code for the same job.
    Voilà!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center