最近我跟進了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?
你能上傳你的fla和xml文件嗎? – Taurayi 2011-02-13 13:00:38