Navigating to MainTimeline from a MovieClip
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Navigating to MainTimeline from a MovieClip

  1. #1
    Senior Member da_hammer's Avatar
    Join Date
    Jul 2003
    Location
    Ritchie Street.
    Posts
    294

    Navigating to MainTimeline from a MovieClip

    Hello,

    Am a newbie to AS 3.0, am trying access the MainTimeLine from a movieClip instance added from Library.
    Am able to remove the same instance, but am not able to navigate to MainTim

    Code:
    // Doesn't Work
    wellPlayed(root).gotoAndStop(120);
    
    // This removal works fine.
    parent.removeChild(wellPlayed);
    am sure am doing something silly here is the full code:

    Code:
    public class BallMc extends MovieClip
    	{
    		protected var originalPosition:Point;
    		public function BallMc()
    		{
    			originalPosition = new Point(x, y);
    			buttonMode = true;
    			addEventListener ( MouseEvent.MOUSE_DOWN, down );
    		}
    		
    		protected function down (event:MouseEvent) :void
    		{
    			parent.addChild(this);
    			startDrag ();
    			stage.addEventListener ( MouseEvent.MOUSE_UP, stageUp );
    		}
    		
    		protected function stageUp(event:MouseEvent ):void
    		{
    			stage.removeEventListener( MouseEvent.MOUSE_UP, stageUp );
    			stopDrag();
    			
    			if( dropTarget )
    			{
    				if( dropTarget.parent.name == "basket")
    				{
    					scaleX = scaleY = 0.2;
    					alpha = 0.2;
    					y = stage.stageHeight - height - 10;
    					
    					buttonMode = false;
    					removeEventListener( MouseEvent.MOUSE_DOWN, down );
    					
    					var wellPlayed : WellPlayed = new WellPlayed();
    					parent.addChild(wellPlayed);
    					
    					wellPlayed.x = stage.stageWidth / 2;
    					wellPlayed.y = stage.stageHeight / 2;	
    					
    					wellPlayed.addEventListener(MouseEvent.CLICK, wellClick);
    					
    					function wellClick(event:MouseEvent):void
    					{
    						wellPlayed(root).gotoAndStop(120);
    						parent.removeChild(wellPlayed);
    						wellPlayed.removeEventListener(MouseEvent.CLICK, wellClick);
    						
    					}
    			
    				}else{
    					returnToOriginalPosition();
    				}
    
    			}else{
    				returnToOriginalPosition();
    			}
    		}
    		
    		protected function returnToOriginalPosition():void
    		{
    			x = originalPosition.x;
    			y = originalPosition.y;
    		}
    		
    	}
    Someone point me in the right direction.

    Thanks in advance.
    Amar
    Last edited by da_hammer; 08-25-2014 at 11:33 AM.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,155
    Hi,

    Have you tried this
    PHP Code:
    event.currentTarget.removeEventListener(MouseEvent.CLICKwellClick);
    MovieClip(event.currentTarget.parent).gotoAndStop(120);
    MovieClip(event.currentTarget.parent).removeChild(event.currentTarget); 
    instead of what you have now?

    perhaps it might be better to put the wellClick function outside of the current function on its own!!
    Last edited by fruitbeard; 08-25-2014 at 12:00 PM. Reason: Swapped e for event

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,155
    Hi,

    If you still have problems it would be easier to see your files, if you can attach them

  4. #4
    Senior Member da_hammer's Avatar
    Join Date
    Jul 2003
    Location
    Ritchie Street.
    Posts
    294

    Re:

    Quote Originally Posted by fruitbeard View Post
    Hi,

    If you still have problems it would be easier to see your files, if you can attach them

    Hi there,

    Apparently the PHP code didn't help me.
    I have attached my files for you, i would really appreciate if you have a loot at the files.
    And point me in the right direction further.

    Thanks in advance.
    Amar
    Attached Files Attached Files

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,155
    Hi,

    the code for BallMc.as works like so
    PHP Code:
    package net.dndgames.dragdrop
    {
        
    import flash.display.MovieClip;
        
    import flash.events.MouseEvent;
        
    import flash.geom.Point;

        public class 
    BallMc extends MovieClip
        
    {
            protected var 
    originalPosition:Point;

            public function 
    BallMc()
            {
                
    originalPosition = new Point(x,y);
                
    buttonMode true;
                
    addEventListenerMouseEvent.MOUSE_DOWNdown );
            }

            protected function 
    down(event:MouseEvent):void
            
    {
                
    parent.addChild(this);
                
    startDrag();
                
    stage.addEventListenerMouseEvent.MOUSE_UPstageUp );
            }

            protected function 
    stageUp(event:MouseEvent ):void
            
    {
                
    stage.removeEventListenerMouseEvent.MOUSE_UPstageUp );
                
    stopDrag();

                if (
    dropTarget)
                {
                    if (
    dropTarget.parent.name == "basket")
                    {
                        
    scaleX scaleY 0.2;
                        
    alpha 0.1;
                        
    stage.stageHeight height 10;

                        
    buttonMode false;
                        
    removeEventListenerMouseEvent.MOUSE_DOWNdown );

                        var 
    wellPlayed WellPlayed = new WellPlayed();
                        
    parent.addChild(wellPlayed);

                        
    wellPlayed.stage.stageWidth 2;
                        
    wellPlayed.stage.stageHeight 2;
                        
    wellPlayed.addEventListener(MouseEvent.CLICKwellClick);
                    }
                    else
                    {
                        
    returnToOriginalPosition();
                    }
                }
                else
                {
                    
    returnToOriginalPosition();
                }
            }

            protected function 
    wellClick(event:MouseEvent):void
            
    {
                
    event.currentTarget.parent.gotoAndStop(120);
                
    event.currentTarget.removeEventListener(MouseEvent.CLICKwellClick);
                
    event.currentTarget.parent.removeChild(event.currentTarget);
            }

            protected function 
    returnToOriginalPosition():void
            
    {
                
    originalPosition.x;
                
    originalPosition.y;
            }

        }

    it's not php, I just use the php tags.

  6. #6
    Senior Member da_hammer's Avatar
    Join Date
    Jul 2003
    Location
    Ritchie Street.
    Posts
    294

    Re:

    Fruitbeard,

    Thanks for your help.

    With the new protected function, it does executes the removeEventListener part.
    but still the following part is not executing, so that my MainTimeline stops at frame number 120:

    PHP Code:
    event.currentTarget.parent.gotoAndStop(120); 
    thanks once again.

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,155
    Hi,

    It does gotoAndStop(120) as I see it doing it here, the /b/ changes to /h/ after ding so

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,155
    Hi,

    Although it works here, this also works,

    BallMc.as
    PHP Code:
    package net.dndgames.dragdrop
    {
        
    import flash.display.MovieClip;
        
    import flash.events.MouseEvent;
        
    import flash.geom.Point;

        public class 
    BallMc extends MovieClip
        
    {
            protected var 
    originalPosition:Point;

            public function 
    BallMc()
            {
                
    originalPosition = new Point(x,y);
                
    buttonMode true;
                
    addEventListenerMouseEvent.MOUSE_DOWNdown );
            }

            protected function 
    down(event:MouseEvent):void
            
    {
                
    parent.addChild(this);
                
    startDrag();
                
    stage.addEventListenerMouseEvent.MOUSE_UPstageUp );
            }

            protected function 
    stageUp(event:MouseEvent ):void
            
    {
                
    stage.removeEventListenerMouseEvent.MOUSE_UPstageUp );
                
    stopDrag();

                if (
    dropTarget)
                {
                    if (
    dropTarget.parent.name == "basket")
                    {
                        
    trace(dropTarget.parent.name);
                        
    scaleX scaleY 0.2;
                        
    alpha 0.1;
                        
    stage.stageHeight height 10;

                        
    buttonMode false;
                        
    removeEventListenerMouseEvent.MOUSE_DOWNdown );

                        var 
    wellPlayed WellPlayed = new WellPlayed();
                        
    parent.addChild(wellPlayed);

                        
    wellPlayed.stage.stageWidth 2;
                        
    wellPlayed.stage.stageHeight 2;
                        
    wellPlayed.addEventListener(MouseEvent.CLICKwellClick);
                    }
                    else
                    {
                        
    returnToOriginalPosition();
                    }
                }
                else
                {
                    
    returnToOriginalPosition();
                }
            }

            protected function 
    wellClick(event:MouseEvent):void
            
    {
                
    MovieClip(root).gotoAndStop(120);
                
    event.currentTarget.removeEventListener(MouseEvent.CLICKwellClick);
                
    event.currentTarget.parent.removeChild(event.currentTarget);
            }

            protected function 
    returnToOriginalPosition():void
            
    {
                
    originalPosition.x;
                
    originalPosition.y;
            }

        }


  9. #9
    Senior Member da_hammer's Avatar
    Join Date
    Jul 2003
    Location
    Ritchie Street.
    Posts
    294
    Fruitbeard,

    I think after sending you the first version file, i have tested one more version with more redundant codes.
    I think that was the issue. Now it works fine.

    Really appreciate your help & Cheers!
    I can't treat you as PayPal operations are limited in India

    I shall buy ya couple of Lagers!
    Kindly do PM me!

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

Poll by Flashkit.com