最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
AS3 动态文本的拖动与旋转
时间:2022-07-02 16:59:58 编辑:袖梨 来源:一聚教程网
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* ...
* @author FLASH023
*/
public class Main extends Sprite
{
private var now_box:TextBox;
public function Main():void {
var _p:int = 12;
while (_p--) {
var _box:TextBox = new TextBox ();
_box.x = 100+Math.random () * 550;
_box.y = 100 + Math.random () * 400;
_box.rotationZ = Math.random () * 360;
_box.addEventListener (MouseEvent.CLICK, onClick);
addChild (_box);
}
}
private function onClick(_evt:MouseEvent ):void {
var _box:TextBox = _evt.target as TextBox;
if (_box) {
now_box&&(now_box.focus = false);
_box.focus = true;
now_box = _box;
}
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.events.MouseEvent;
class TextBox extends Sprite {
private var r_btn:Sprite;
private var p_txt:TextField;
public function TextBox():void {
p_txt = addChild (new TextField) as TextField ;
p_txt.autoSize = "left";
p_txt.text = "测试文本";
p_txt.selectable = false;
p_txt.mouseEnabled = false;
p_txt.x = width * -.5;
p_txt.y = height * -.5;
p_txt.borderColor = 0x333399;
r_btn = addChild (new Sprite) as Sprite;
r_btn.graphics.beginFill (0x333399,.6);
r_btn.graphics.drawCircle (0, 0, 5);
r_btn.x = p_txt.width * .5;
r_btn.y = -p_txt.height * .5;
r_btn.visible = false;
r_btn.buttonMode = true;
addEventListener (MouseEvent.MOUSE_DOWN, mouseDown );
}
private function mouseDown(_evt:MouseEvent ):void {
if (_evt.target != r_btn) {
startDrag ();
}else{
addEventListener (Event.ENTER_FRAME, startRing );
}
stage.addEventListener (MouseEvent.MOUSE_UP, mouseUp);
}
private function startRing(_evt:Event):void {
rotationZ = Math.atan2 (parent.mouseY - y, parent.mouseX - x) / Math.PI * 180;
}
private function mouseUp(_evt:MouseEvent ):void {
stopDrag();
removeEventListener (Event.ENTER_FRAME, startRing );
stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUp);
}
public function set focus(_b:Boolean):void {
r_btn.visible = _b;
p_txt.border = _b;
}
}
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22