博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[ActionScript 3.0] AS3动态改变注册点
阅读量:4319 次
发布时间:2019-06-06

本文共 4860 字,大约阅读时间需要 16 分钟。

package{    import flash.display.DisplayObject;    import flash.display.DisplayObjectContainer;    import flash.display.GradientType;    import flash.display.Shape;    import flash.display.Sprite;    import flash.events.MouseEvent;    import flash.geom.Matrix;    import flash.geom.Point;    import flash.text.TextField;    import flash.utils.getQualifiedClassName;        /**     * @author Frost.Yen     * @E-mail 871979853@qq.com     * @create 2015-10-12 下午4:28:13     *     */    [SWF(width="800",height="600")]    public class DynamicRegistration extends Sprite    {        private var _obj:Sprite;        private var _pot:Shape;        private var _value:Number = 1;        private var _property:Array = ["width","height","scaleX","scaleY","rotation"];        private var _currPro:String = "width";        public function DynamicRegistration()        {            initViews();            initEventListeners();        }        private function initViews():void        {            var matr:Matrix = new Matrix();            matr.createGradientBox(480, 100, 0, 0, 0);            _pot = new Shape();            _obj = new Sprite();            _obj.graphics.beginGradientFill(GradientType.LINEAR,[0xFF0000, 0xFF00FF],[1,1],[0,255],matr);            _obj.graphics.drawRect(0,0,200,150);            _obj.graphics.endFill();            _obj.x = (stage.stageWidth - _obj.width )*0.5;            _obj.y = (stage.stageHeight - _obj.height)*0.5;            _pot.graphics.beginFill(0,.5);            _pot.graphics.drawCircle(0,0,5);            _pot.graphics.endFill();            _pot.x = _obj.x;            _pot.y = _obj.y;            for(var i:int = 0;i<_property.length;i++){                var pro:TextField = getButton("   "+_property[i]+"   ",this,stage.stageWidth-100,150+30*i,_property[i]);                pro.addEventListener(MouseEvent.CLICK,onSelectProperty);            }            setProState(_currPro);            this.addChild(_obj);            this.addChild(_pot);        }        private function initEventListeners():void        {            _obj.addEventListener(MouseEvent.CLICK,onClick);        }                private function onClick(e:MouseEvent):void        {            _value = _obj[_currPro];            switch(_currPro){                case _property[0]:                case _property[1]:                    _value+=10;                    break;                case _property[2]:                case _property[3]:                    _value+=0.2;                    break;                case _property[4]:                    _value+=20;                    break;            }            dynamicRegistration1(_obj,new Point(_obj.mouseX,_obj.mouseY),_currPro,_value);            _pot.x = mouseX;            _pot.y = mouseY;        }        private function onSelectProperty(e:MouseEvent):void        {            _currPro = e.currentTarget.name;            setProState(_currPro);        }        private function setProState(pro:String):void        {            for(var i:int = 0;i<_property.length;i++){                if(_property[i] == pro){                    (this.getChildByName(_property[i]) as TextField).borderColor = 0x00ffff;                 }else{                    (this.getChildByName(_property[i]) as TextField).borderColor = 0x222222;                }            }        }        private function getButton(text:String,parent:Sprite,x:Number=0,y:Number=0,name:String=null):TextField        {            var textButton:TextField = new TextField();            textButton.autoSize = "left";            textButton.width = 110;            textButton.height = 38;            textButton.selectable = false;            textButton.border = true;            textButton.borderColor = 0x222222;            textButton.background = true;            textButton.backgroundColor = 0xaaaaaa;            textButton.htmlText = ""+text+"";            textButton.x = x;            textButton.y = y;            if(name!=null){                textButton.name = name;            }            parent.addChild(textButton);            return textButton;        }                /**         * 动态改变注册点         * target     改变注册点的对象         * point     新的注册点         * pro         需要改变的属性         * value     新的属性值         */        private function dynamicRegistration1(target:DisplayObject,point:Point,pro:String,value:Number):void        {            //转换为全局坐标            var A:Point=target.parent.globalToLocal(target.localToGlobal(point));            if(pro == "x"||pro == "y"){                target[pro] = value-point[pro];            }else{                target[pro]=value;                var B:Point = target.parent.globalToLocal(target.localToGlobal(point));                //把注册点从B点移到A点                target.x+=A.x-B.x;                target.y+=A.y-B.y;            }        }    }    }

 

转载于:https://www.cnblogs.com/frost-yen/p/4874445.html

你可能感兴趣的文章
Java魔法堂:找外援的利器——Runtime.exec详解
查看>>
mysql数据库存放路径
查看>>
TestNG(五)常用元素的操作
查看>>
解决 Visual Studio 点击添加引用无反应的问题
查看>>
通过镜像下载Android系统源码
查看>>
python字符串格式化 %操作符 {}操作符---总结
查看>>
windows 不能在 本地计算机 启动 Apache
查看>>
iOS开发报duplicate symbols for architecture x86_64错误的问题
查看>>
Chap-6 6.4.2 堆和栈
查看>>
【Java学习笔记之九】java二维数组及其多维数组的内存应用拓展延伸
查看>>
C# MySql 连接
查看>>
sk_buff Structure
查看>>
oracle的级联更新、删除
查看>>
多浏览器开发需要注意的问题之一
查看>>
Maven配置
查看>>
HttpServletRequest /HttpServletResponse
查看>>
SAM4E单片机之旅——24、使用DSP库求向量数量积
查看>>
从远程库克隆库
查看>>
codeforces Unusual Product
查看>>
hdu4348 - To the moon 可持久化线段树 区间修改 离线处理
查看>>