mouse event emulation

by www0z0k
♥0 | Line 37 | Modified 2011-11-11 05:57:12 | MIT License
play

ActionScript3 source code

/**
 * Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6CEJ
 */

package {
    import flash.events.MouseEvent;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextField;
    import flash.ui.Keyboard;
    import flash.events.KeyboardEvent;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var tf:TextField = new TextField();
        private var b1:Sprite = new Sprite();
        private var b2:Sprite = new Sprite();
        public function FlashTest() {
             addChild(tf);
             tf.autoSize = TextFieldAutoSize.LEFT;             
            addChild(b1);  
            addChild(b2);
            b1.x = 100;
            b2.x = 200;
            drawRect(b1, 0xff0000);
            drawRect(b2, 0x0000ff);
            b1.addEventListener(MouseEvent.CLICK, b1Clicked);
            b2.addEventListener(MouseEvent.CLICK, b2Clicked);
            
        }
        
        private function b1Clicked(e:MouseEvent):void{
            tf.text = 'b1';
            b2.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
        }
        private function b2Clicked(e:MouseEvent):void{
            tf.text += 'b2';
        }

        
        private function drawRect(s:Sprite, col:int):void{
            s.graphics.beginFill(col);
            s.graphics.drawRect(0,0,75,75);
            s.graphics.endFill();
        }

    }
}