SimpleButton Class in Actionscript 3.0
I was playing with the SimpleButton class in AS 3.0 and decided it would be nice to post a simple example with some tips.
The SimpleButton class allows you to create—you guessed it—simple buttons. It's basically a dynamic way to create Buttons with predefined states used in Flash.
Here's the visual (not much to look at):
And the code:
package {
import flash.display.Sprite;
import flash.display.SimpleButton;
public class Source extends Sprite {
public var button:SimpleButton;
private var numButtonWidth:Number = 100;
private var numButtonHeight:Number = 50;
public function Source() {
button = new SimpleButton;
button.upState = drawButtonState(0xDAD8F3);
button.overState = drawButtonState(0x4F42C6);
button.downState = drawButtonState(0xDDF2FF);
button.hitTestState = drawButtonState(0xDDF2FF);
button.useHandCursor = true;
this.addChild(button);
}
private function drawButtonState(rgb:uint):Sprite {
var sprite:Sprite = new Sprite();
sprite.graphics.lineStyle(4,0x33621E,1);
sprite.graphics.beginFill(rgb);
sprite.graphics.drawRoundRect(((this.stage.
stageWidth/2)-(numButtonWidth/2)),((this.
stage.stageHeight/2)-(numButtonHeight/2)),
numButtonWidth,numButtonHeight,10,10);
return sprite;
}
}
}

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home