A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: how to addressing the MC as a button in AS3

Threaded View

  1. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You have 2 possibilities.
    1. Create a movie with a movieclip in the library and link it to the class ChildSprite.
    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        public class 
    ChildSprite extends MovieClip
        
    {
            public function 
    ChildSprite ()
            {
                
    this.buttonMode true;
                
    this.addEventListener("click"onClick);
            }
            private function 
    onClick (obj:Object)
            {
                
    trace("Hello World");
            }
        }

    Then create a document class.
    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        
    import ChildSprite;
        public class 
    Example extends MovieClip
        
    {
            private var 
    myBut:MovieClip;
            public function 
    Example()
            {
                var 
    myBut:ChildSprite = new ChildSprite();
                
    addChild(myBut);
                
    myBut.100;
                
    myBut.100;
            }
        }

    In the Document class field in the fla add: Example and test movie.

    2. Create a movie with a movieclip in the library and link it to the class ChildSprite_2, which is basically empty.
    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        public class 
    ChildSprite_2 extends MovieClip
        
    {
            public function 
    ChildSprite_2 ()
            {
            }
        }

    Then create a document class.
    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        
    import ChildSprite_2;
        public class 
    Example_2 extends MovieClip
        
    {
            private var 
    myBut:MovieClip;
            public function 
    Example_2 ()
            {
                var 
    myBut:ChildSprite_2 = new ChildSprite_2 ();
                
    addChild(myBut);
                
    myBut.100;
                
    myBut.100;
                
    myBut.buttonMode true;
                
    myBut.addEventListener("click"onClick);
            }
            private function 
    onClick (obj:Object)
            {
                
    trace("Hello World");
            }
        }

    This last example is closer to the original stage example.

    A third possibility is this to mark the movieclip as button.
    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        public class 
    ChildSprite_2 extends MovieClip
        
    {
            public function 
    ChildSprite_2 ()
            {
                
    this.buttonMode true;
            }
        }

    and then an above script as document class without the buttonmode.
    Last edited by cancerinform; 08-22-2006 at 08:10 AM.
    - The right of the People to create Flash movies shall not be infringed. -

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