AS3 example Button: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
(New page: == Program == package { import flash.display.Sprite; import flash.text.TextField; import flash.events.*; public class ButtonInteractivity extends Sprite { ...)
 
Line 5: Line 5:
       import flash.text.TextField;
       import flash.text.TextField;
       import flash.events.*;
       import flash.events.*;
 
      public class ButtonInteractivity extends Sprite {
   
   
          private var button:Sprite = new Sprite();
   
   
      public class ButtonInteractivity extends Sprite {
          private var button:Sprite = new Sprite();
           public function ButtonInteractivity() {
           public function ButtonInteractivity() {
               drawButton()
               drawButton()
Line 16: Line 15:
               addChild(button);
               addChild(button);
           }
           }
       
       
           private function drawButton():void {
           private function drawButton():void {
               var textLabel:TextField = new TextField()
               var textLabel:TextField = new TextField()
Line 29: Line 28:
               button.addChild(textLabel)
               button.addChild(textLabel)
           }
           }
 
           private function mouseDownHandler(event:MouseEvent):void {
           private function mouseDownHandler(event:MouseEvent):void {
               button.x += 20
               button.x += 20

Revision as of 23:04, 1 November 2007

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

...