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 = "<a href='event:#'>"+text+"</a>";
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;
}
}
} }

[ActionScript 3.0] AS3动态改变注册点的更多相关文章

  1. [ActionScript 3.0] AS3.0 动态加载显示内容

    可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...

  2. [ActionScript 3.0] as3处理xml的功能和遍历节点

    as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...

  3. [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains

    简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...

  4. [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains

    简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...

  5. [ActionScript 3.0] AS3.0和AS2.0的相互通信

    AS3和AS2之间的通信,最好的方式可能就是LocalConnection了. AS2向AS3发送数据,即AS2调用AS3的函数: as2.0代码(按钮上写的发送信息代码): on (release) ...

  6. [ActionScript 3.0] AS3.0 对象在矩形范围随机运动

    package com.views { import flash.display.Bitmap; import flash.display.MovieClip; import flash.displa ...

  7. [ActionScript 3.0] AS3.0 本机鼠标指针

    Flash Player 10.2添加了内置的本机鼠标指针(native mouse cursor)支持,虽然在之前的版本里我们可以侦听MouseEvent事件来模拟鼠标指针,但是在有了原生的本机鼠标 ...

  8. [ActionScript 3.0] AS3调用百度天气预报查询API

    接口说明 根据经纬度/城市名查询天气的结果 接口示例 http://api.map.baidu.com/telematics/v3/weather?location=成都&output=jso ...

  9. [ActionScript 3.0] AS3.0 让一个视频无缝循环播放的一个偏方

    一个视频要循环播放,通常的办法都是播放完后再重新播放,但是不可避免的播放结束和重新开始播放这个时间点上会有停顿,如何解决这个问题,说个偏方吧! package com.views { import f ...

随机推荐

  1. 设置EDIUS字幕时有哪些要注意的

    我们在用EDIUS添加字幕,有时候可能会遇到以下麻烦.例如有的字体在EDIUS中找不到,诗歌的排版问题还有怎么给字幕加光效等等.今天小编主要来给大家解决这三个问题,让你们知道EDIUS字幕设置时应该注 ...

  2. axure复用-自定义组件,母版(模板)

    组件(控件)是用于设计线框图的用户界面元素.在组件(控件)面板中包含有常用的控件库,如按钮.图片.文本框等.从组件面板中拖动一个控件到线框图区域中,就可以添加一个组件.组件可以从一个线框图中被拷贝(C ...

  3. SVG添加链接(转载)

    转载地址:http://tech.techweb.com.cn/thread-258715-1-1.html 最基本的交互形式是链接.在 SVG 中,通过一个 <a> 标签提供链接,这与 ...

  4. 【转】svn服务器IP修改后,本地怎么跟新svn同步,svn relocate 操作

    本文来源:http://www.kukaka.org/home/showonews/444 1.进入工作复本 cd ~/test 2.查看仓库地址(URL) svn info 路径: .    URL ...

  5. Android软键盘遮挡的四种解决方案

    问题概述 在编辑框输入内容时会弹出软键盘,而手机屏幕区域有限往往会遮住输入界面,我们先看一下问题效果图: 输入用户名和密码时,系统会弹出键盘,造成系统键盘会挡住文本框的问题,如图所示: 输入密码时输入 ...

  6. android中的EditView控件

    android中的EditView控件 EditText继承关系:View-->TextView-->EditText ,EditText是可编辑文本框 1.EditText默认情况下,光 ...

  7. Nginx出现413 Request Entity Too Large错误解决方法

    Nginx出现的413 Request Entity Too Large错误,这个错误一般在上传文件的时候出现,打开nginx主配置文件nginx.conf,找到http{}段,添加 解决方法就是 打 ...

  8. ORA-01109:数据库未打开

    ORA-01109:数据库未打开 在此之前做了这样一操作,在plsql创建了2表空间,由于装的是oracle精简版所以创建表空间大小超过4G就不能创建,然后我就手动把表空间给删除了,回收站也给删了,问 ...

  9. Hive(七):HQL DML

    HQL DML 主要涉到对Hive表中数据操作,包含有:load.INSERT.DELETE.EXPORT and IMPORT,详细资料参见:https://cwiki.apache.org/con ...

  10. javascript util.js

    //根据Id获得页面元素 function $(para) {    return document.getElementById(para);} //创建一个新的元素function createE ...