动态修改MC的注册点

2006.8.19 10:31 [ 工作 ] 评论(2) , 阅读(3678) | |
  文章地址:http://www.darronschall.com/weblog/archives/000054.cfm
  下载地址:http://www.darronschall.com/downloads/DynamicRegistration.zip

  演示:

  使用方法:

import com.darronschall.DynamicRegistration;

// Assume there is an instance named square_mc on the stage that
// has the correct linkage as described above
var square_mc:DynamicRegistration;

// The square_mc has an original registration at 0,0 so
// let's change that to 10, 60 at runtime.
square_mc.setRegistration(10, 10);

// Now whenever we access a property of the square_mc that deals
// with the registration point, use a "2" after the property name...
// These are the available properties:
square_mc._x2 = 4;
square_mc._y2 = 7;
square_mc._rotation2 = 40;
square_mc._xscale2 = 140;
square_mc._yscale2 = 80;
// square_mc._xmouse2 is readonly
// square_mc._ymouse2 is readonly


  核心代码:

// special thanks to Robert Penner (www.robertpenner.com) for providing the
// original code for this in ActionScript 1 on the FlashCoders mailing list

dynamic class com.darronschall.DynamicRegistration {
      
       private function DynamicRegistration() {
              
       }
      
       public static function initialize(target_mc):Void {
              var p = _global.com.darronschall.DynamicRegistration.prototype;
              target_mc.xreg = 0;
              target_mc.yreg = 0;
              target_mc.setRegistration = p.setRegistration;
              target_mc.setPropRel = p.setPropRel;
              with (target_mc) {
                     addProperty("_x2", p.get_x2, p.set_x2);
                     addProperty("_y2", p.get_y2, p.set_y2);
                     addProperty("_xscale2", p.get_xscale2, p.set_xscale2);
                     addProperty("_yscale2", p.get_yscale2, p.set_yscale2);
                     addProperty("_rotation2", p.get_rotation2, p.set_rotation2);
                     addProperty("_xmouse2", p.get_xmouse2, null);
                     addProperty("_ymouse2", p.get_ymouse2, null);
              }
       }

       private function setRegistration(x:Number, y:Number):Void {
              this.xreg = x;
              this.yreg = y;
       }
      
       private function get_x2():Number {
              var a = {x:this.xreg, y:this.yreg};
              this.localToGlobal(a);
              this._parent.globalToLocal(a);
              return a.x;
       }
      
       private function set_x2(value:Number):Void {
              var a = {x:this. xreg, y:this. yreg};;
              this.localToGlobal(a);
              this._parent.globalToLocal(a);
              this._x += value - a.x;
       }

       private function get_y2():Number {
              var a = {x:this.xreg, y:this.yreg};
              this.localToGlobal(a);
              this._parent.globalToLocal(a);
              return a.y;
       }
      
       private function set_y2(value:Number):Void {
              var a = {x:this.xreg, y:this.yreg};
              this.localToGlobal(a);
              this._parent.globalToLocal(a);
              this._y += value - a.y;
       }
      
       private function set_xscale2(value:Number):Void {
              this.setPropRel("_xscale", value);
       }
      
       private function get_xscale2():Number {
              return this._xscale;
       }
      
       private function set_yscale2(value:Number):Void {
              this.setPropRel("_yscale", value);
       }
      
       private function get_yscale2():Number {
              return this._yscale;
       }
      
       private function set_rotation2(value:Number):Void {
              this.setPropRel("_rotation", value);
       }
      
       private function get_rotation2():Number {
              return this._rotation;
       }
      
       private function get_xmouse2():Number {
              return this._xmouse - this.xreg;
       }
      
       private function get_ymouse2():Number {
              return this._ymouse - this.yreg;
       }

       private function setPropRel(property:String, amount:Number):Void {
              var a = {x:this.xreg, y:this.yreg};
              this.localToGlobal (a);
              this._parent.globalToLocal (a);
              this[property] = amount;
              var b = {x:this.xreg, y:this.yreg};
              this.localToGlobal (b);
              this._parent.globalToLocal (b);
              this._x -= b.x - a.x;
              this._y -= b.y - a.y;
       }
}


Tags: ,
有人在2009/10/21 09:24说:
shockkillkillkillkillkillkillkillkillkillkillkillkillkill
tenlin 回复于 2009/10/21 09:58
呵呵,代码插件出来点问题,已经修复,别砍我了
有人在2009/10/21 09:24说:
loveshuaistupidzan
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   可以直接留言
网址   电邮   [注册]