论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

AS3 动态文本的拖动与旋转

文章类别:Flash AS | 发表日期:2010-1-31 14:28:22

代码:

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;
        }
    }

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058