AS3 example Button

The educational technology and digital learning wiki
Revision as of 00:04, 2 November 2007 by Widged (talk | contribs) (New page: == Program == package { import flash.display.Sprite; import flash.text.TextField; import flash.events.*; public class ButtonInteractivity extends Sprite { ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Program

 package {
     import flash.display.Sprite;
     import flash.text.TextField;
     import flash.events.*;


     public class ButtonInteractivity extends Sprite {
         private var button:Sprite = new Sprite();
         public function ButtonInteractivity() {
             drawButton()
             button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
             addChild(button);
         }
       
         private function drawButton():void {
             var textLabel:TextField = new TextField()
             button.graphics.clear();
             button.graphics.beginFill(0xD4D4D4);
             button.graphics.drawRoundRect(0, 0, 80, 25, 10, 10);
             button.graphics.endFill();
             textLabel.text = "Click Me!";
             textLabel.x = 10;
             textLabel.y = 5;
             textLabel.selectable = false;
             button.addChild(textLabel)
         }
         private function mouseDownHandler(event:MouseEvent):void {
             button.x += 20
             if (button.x > 200) { button.x = 0}
         }
     }
 }

Walkthrough

...