Playpause Button in Actionscript 3
I have provided code for a play/pause button that can be used for a video player or whatever you require this button for. I have created the play and pause shapes using the AS3 drawing API and have added a mouse click event which toggles between the play and pause states.
/**
* PLAY/PAUSE BTN CLASS
* CREATED BY ILIKE2FLASH.COM
*
**/
package com.ilike2flash {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class PlayPauseBtn extends Sprite {
private var tri:Sprite;
private var pau:Sprite;
public function PlayPauseBtn() {
buttonMode = true;
var bg:Shape = new Shape();
bg.graphics.beginFill(0x000000,0.8);
bg.graphics.drawEllipse(0, 0, 82, 82);
bg.graphics.endFill();
addChild(bg);
tri = new Sprite();
tri.graphics.beginFill(0xffffff);
tri.graphics.moveTo(0, 0);
tri.graphics.lineTo(30, 18);
tri.graphics.lineTo(0, 36);
tri.graphics.endFill();
tri.x = 32;
tri.y = 23;
addChild(tri);
pau = new Sprite();
pau.graphics.beginFill(0xffffff);
pau.graphics.drawRect(0, 0, 11, 40);
pau.graphics.drawRect(18, 0, 11, 40);
pau.graphics.endFill();
pau.x = 26;
pau.y = 21;
pau.visible = false;
addChild(pau);
addEventListener(MouseEvent.CLICK, clicked);
}
public function clicked(e:MouseEvent=null):void
{
tri.visible = !tri.visible;
pau.visible = !pau.visible;
}
}
}
To use the button, you create a new instance of the PlayPauseBtn class like below.
import com.ilike2flash.PlayPauseBtn; var playpausebtn:PlayPauseBtn = new PlayPauseBtn(); addChild(playpausebtn);



0 comments:
Post a Comment