2011-02-13 161 views
0

最近我跟进了AS2中的3d旋转木马,但我正在使用它并在AS3中制作它。是否有任何可能的方式转换代码,以便传送带可以在AS3中工作?将Actionscript 2代码转换为ActionScript 3

下面是对AS2转盘代码:

import mx.utils.Delegate; 

var numOfItems:Number; 
var radiusX:Number = 300; 
var radiusY:Number = 75; 
var centerX:Number = Stage.width/2; 
var centerY:Number = Stage.height/2; 
var speed:Number = 0.05; 
var perspective:Number = 130; 
var home:MovieClip = this; 

var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",10000); 
tooltip._alpha = 0; 

var xml:XML = new XML(); 
xml.ignoreWhite = true; 

xml.onLoad = function() 
{ 
    var nodes = this.firstChild.childNodes; 
    numOfItems = nodes.length; 
    for(var i=0;i<numOfItems;i++) 
    { 
     var t = home.attachMovie("item","item"+i,i+1); 
     t.angle = i * ((Math.PI*2)/numOfItems); 
     t.onEnterFrame = mover; 
     t.toolText = nodes[i].attributes.tooltip; 
     t.icon.inner.loadMovie(nodes[i].attributes.image); 
     t.r.inner.loadMovie(nodes[i].attributes.image); 
     t.icon.onRollOver = over; 
     t.icon.onRollOut = out; 
     t.icon.onRelease = released; 
    } 
} 

function over() 
{ 
    home.tooltip.tipText.text = this._parent.toolText; 
    home.tooltip._x = this._parent._x; 
    home.tooltip._y = this._parent._y - this._parent._height/2; 
    home.tooltip.onEnterFrame = Delegate.create(this,moveTip); 
    home.tooltip._alpha = 100; 
} 

function out() 
{ 
    delete home.tooltip.onEnterFrame; 
    home.tooltip._alpha = 0; 
} 

function released() 
{ 
    trace(this._parent.toolText); 
} 

function moveTip() 
{ 
    home.tooltip._x = this._parent._x; 
    home.tooltip._y = this._parent._y - this._parent._height/2; 
} 

xml.load("icons.xml"); 

function mover() 
{ 
    this._x = Math.cos(this.angle) * radiusX + centerX; 
    this._y = Math.sin(this.angle) * radiusY + centerY; 
    var s = (this._y - perspective) /(centerY+radiusY-perspective); 
    this._xscale = this._yscale = s*100; 
    this.angle += this._parent.speed; 
    this.swapDepths(Math.round(this._xscale) + 100); 
} 

this.onMouseMove = function() 
{ 
    speed = (this._xmouse-centerX)/2500; 
} 

当我在AS3中添加此代码我收到以下错误:

Scene 1, Layer 'Layer 1', Frame 1, Line 1 1172: Definition mx.utils:Delegate could not be found. Scene 1, Layer 'Layer 1', Frame 1, Line 1 1172: Definition mx.utils:Delegate could not be found. Scene 1, Layer 'Layer 1', Frame 1, Line 41 1120: Access of undefined property Delegate. Scene 1, Layer 'Layer 1', Frame 1, Line 6 1119: Access of possibly undefined property width through a reference with static type Class. Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property height through a reference with static type Class.

我是很新的AS2和AS3,但经过一番研究,我的理解是import mx.utils.Delegate;是AS3中不再需要的,因为它已经委托和他们已经建立在这样的代码,所以我删除的是线1和线41的委托,并得到了两个错误:

Scene 1, Layer 'Layer 1', Frame 1, Line 6 1119: Access of possibly undefined property width through a reference with static type Class. Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property height through a reference with static type Class.

现在我无法弄清楚如何做到这一点有人可以帮助我从AS2把这段代码转换至AS3?

+0

你能上传你的fla和xml文件吗? – Taurayi 2011-02-13 13:00:38

回答

1

你有相当多的事情来解决这里:

你的鼠标事件需要改变,以AS3调用 t.icon.onRollOver =超过,在AS3看起来更像t.icon.addEventListener (MouseEvent.ROLL_OVER,over);

attachMovie不再用于as3。 需要为ActionScript导出你想从一个独特的类名的库来获得,然后使用新someName(电影);来创建它。然后,它必须被添加到显示列表与的addChild

的onEnterFrame没有在AS3中,你需要更多的像这样创建一个enterFrame事件:**的addEventListener(Event.ENTER_FRAME,someFunction);

委托没有在AS3使用。

上_x,_y,_parent,_alpha等标志已在AS3中被删除。只是用X,Y,父母,阿尔法等

swapDepths则已经从AS3删除,您需要使用显示列表添加/删除/交换水平。

听起来像是你可能需要上晚自习AS3一点,才能妥善处理这一个!尝试检查此链接以比较as2和as3功能。

http://www.actionscriptcheatsheet.com/downloads/as3cs_migration.pdf

+0

感谢您的信息,但即时通讯真的是新的尝试转换它,取代每个动作,但我可以找到它,在迁移列表中已被删除的动作没有更换,所以我不知道该怎么办 – shkz 2011-02-15 13:56:02