2011-02-13 162 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