Scenario:
You would like to create the visual portion of a GUI object in the Flash IDE, because it’s easier to draw with the tools provide than it is to “draw” with code. How do you then make this item functional? Extend it with a custom class, of course!
- Draw a rectangle with the rectangle tool.
- Convert the rectangle to a MovieClip symbol.
- Name it RectangleMC.
- Set the Class to RectangleMC (same as the name).
- Set the Base Class to your new custom class (i.e. com.miketmoore.gui.Rectangle).
- That’s it!
Here is a super-basic class that virtualizes the action of a two-position switch. If you create a two-frame MovieClip and add Switch as it’s class in the properties panel, then clicking the MC will move it to the first and second frames, respectively.
package Switch {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Switch extends MovieClip {
private var _currentState:Boolean = false;
public function Switch():void {
addEventListener(MouseEvent.CLICK, switchClicked);
}
private function switchClicked($event:MouseEvent):void {
if(_currentState) {
_currentState = false;
gotoAndStop(1);
} else {
_currentState = true;
gotoAndStop(2);
}
}
public function get currentState():Boolean {
return _currentState;
}
}
}
Check out the new image gallery I have developed in Flash and ActionScript 3.0. It is installed on my main portfolio web site. You can also download it here:
