2010-11-23 97 views
0

以下代碼返回以下運行時錯誤。爲什麼?ActionScript - 補間問題

代碼:

package 
{ 
import flash.display.Sprite; 
import fl.transitions.Tween; 
import fl.transitions.easing.Regular; 
import fl.transitions.TweenEvent; 

public class Test extends Sprite 
    { 
    private var myNumber:Number; 
    private var myTween:Tween; 

    public function Test() 
     { 
     myNumber = -12; 
     myTween = new Tween(this, "myNumber", Regular.easeIn, myNumber, 0, 5, true); 
     myTween.addEventListener(TweenEvent.MOTION_CHANGE, tweenChangeEventHandler); 
     } 

    private function tweenChangeEventHandler(evt:TweenEvent):void 
     { 
     trace(myNumber) 
     } 
    } 
} 

運行時錯誤:

ReferenceError: Error #1056: Cannot create property myNumber on Test. 
    at fl.transitions::Tween/setPosition() 
    at fl.transitions::Tween/set position() 
    at fl.transitions::Tween() 
    at Test() 

回答

1

它認爲吐溫需要公共變量(或的getter/setter方法),以改變他們。嘗試將您的變量更改爲公共變量。

+0

啊,當然!傻我。我並沒有把這個補間課視爲外在的。感謝Mattias。 – TheDarkIn1978 2010-11-23 21:54:42