2016-08-25 67 views
1

當前從舞臺上獲得文本,我想登臺並停在舞臺上的特定位置(97,233.10)。我有點困惑在哪裏停止它和使用什麼代碼?滾動文本字段幫助as3

addEventListener(Event.ENTER_FRAME, mcInfo); 

function mcInfo (e:Event):void { 

//check position of logo 
//if inside the stage move left to right 
//if outside stage reposition 

if (info.x<stage.stageWidth) { 
    info.x+=30; 
    stop(); 
    } else { 
     //reset position 
     info.x=-450; 
    } 
} 

乾杯!

它還看來,當我翻閱我的其他網頁的Flash現在返回一個輸出誤差:

TypeError: Error #1009: Cannot access a property or method of a null object reference. 
    at finaldesign_fla::MainTimeline/mcInfo() 

回答

0

在if語句中,我們檢查對象是否超出目標位置,如果有,則停止循環。否則繼續增加對象的位置。

targetPosition = {x:97, y:233.10}; 

addEventListener(Event.ENTER_FRAME, mcInfo); 

function mcInfo(e:Event) { 
    if (info.x >= targetPosition.x) { 
     info.x = targetPosition.x; 
     removeEventListener(Event.ENTER_FRAME, mcInfo); 
    } else { 
     info.x += 30; 
    } 
} 
+0

謝謝你。但是我怎樣才能讓它停在那個位置(97,233.10)呢? 它仍然循環着那行代碼? – ConfusedDreamweaverUser

+0

這行看起來沒有必要** if(info.x dxb

+0

我該如何將它實現到我的代碼中以停止在x = 97?仍然有點難倒。 – ConfusedDreamweaverUser

0

確保信息是在舞臺上,並嘗試添加:

if(info != null && stage != null)