2012-12-05 18 views
1

我儘量讓簡單的程序,在AS 3, 這是情景: 我有一個影片剪輯的鏈接名稱是英雄, 我想移動英雄向右以速度爲2,如果hero.x = 200,然後將英雄的位置x = 200停止,這是我簡單的代碼:移動影片剪輯與X向右,y座標[動作3.0]自動



    var hero:Hero = new Hero(); 
     hero.x = 0; 
     hero.y = 300; 
     addChild(hero); 

    addEventListener(Event.ENTER_FRAME, animateHero); 
    function animateHero(event:Event) { 

    if (hero.x <= 200){ 
     hero.play(); 
     } else { 
     hero.currentFrame(stop); 
     } 
     hero.x += 2; 
    } 

我試試這個代碼,它正在運行,但顯示重複的錯誤消息輸出面板:



    TypeError: Error #1006: value is not a function. 
     at SpriteMovement_fla::MainTimeline/animateHero() 

我的問題:

是我的代碼錯了嗎?如果是這樣,請告訴我代碼是否正確。

+0

我猜停止是currentFrame中的問題(停止) - 你是否定義了停止enywhere? –

+0

不,我只是想在英雄x = 200時停止英雄。請告訴我該怎麼辦.. – D2N

回答

1
var hero:Hero = new Hero(); 
    hero.x = 0; 
    hero.y = 300; 
    addChild(hero); 
    hero.play(); 
addEventListener(Event.ENTER_FRAME, animateHero); 
function animateHero(event:Event) { 

    if (hero.x <= 200){ 
     hero.x += 2; 
    } else { 
     hero.stop(); 
     removeEventListener(Event.ENTER_FRAME, animateHero); 
    } 
} 

我認爲這是你想要的。

「currentFrame」是一個值而不是函數。這就是顯示錯誤的原因。

+0

謝謝兄弟.. 你的幫助很有用.. 現在英雄可以自動運行和停止 – D2N

0

如果我沒有弄錯(很久以前),您可以使用hero.stop()而不是currentFrame(stop)。我認爲這個錯誤是由於AS3不知道英雄是一個動畫片段而產生的,因此將其轉換爲動畫片段會使Flash知道可以在英雄上調用啓動和停止功能。

+0

以前我試過使用hero.stop(); 是的英雄可以停止移動,但他仍然運行,不能停止。 – D2N