She walks in beauty like the night // Hypnotising the silence with her powers // Armageddon is bedding this picture alright // My Marilyn come to slum for an hour. An actionscript and music blog.

Buttons in AS3

Posted: February 13th, 2009 | Author: Janice | Filed under: Uncategorized | Tags: , | No Comments »

Somewhere above your constructor:

1
2
3
4
import flash.ui.Mouse;
import flash.events.*;
...
var myButton:MovieClip;

Create an instance of your button:

1
2
3
myButton = new ButtonClass(); 
myButton.x = 10; 
// apply properties here

Add event listeners and click handling function:

1
2
3
4
5
6
7
8
myButton.addEventListener(MouseEvent.CLICK, clickHandler); // event listener   
 
private function clickHandler(e:MouseEvent) {
   buttonText.text = "button clicked";
   var myTimer:Timer = new Timer(2000, 1); 
   myTimer.addEventListener(TimerEvent.TIMER, timerListener); 
   myTimer.start(); 
  }

Custom Cursors in AS3

Posted: February 13th, 2009 | Author: Janice | Filed under: Uncategorized | Tags: , | No Comments »

Here is how to have a custom mouse cursor in AS3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package { 
 
import flash.display.Sprite;
import flash.text.TextField;
import flash.ui.Mouse;
import flash.events.*;
import flash.utils.Timer;
 
public class CustomCursor extends Sprite {
 
 private var myCursor:cursor = new cursor();  
 
   public function CustomCursor():void {
   Mouse.hide();   
   addChild(cursorText);
 
    addChild(myCursor);
    myCursor.addEventListener(Event.ENTER_FRAME, init);
  }
 
  private function init(e:Event):void {     
     myCursor.mouseEnabled = false;
     myCursor.x = mouseX;
     myCursor.y = mouseY;
   }
 
      } // end class 
} // end package

( CustomCursor.fla, CustomCursor.as )