2012-12-07 42 views
0

我想從類文件在我的FLA的主時間線上觸發一個函數。我通常可以通過論壇帖子找到解決方案,但我看到的所有內容都無濟於事。在班級的主時間線上觸發一個功能?

繼承人我現在的代碼,但它似乎並沒有工作。

//this is the code in my as3 class file 
var e:Event = new Event("runFunc",true)     dispatchEvent(e) 

//here is the code in my .fla  
addEventListener("runFunc", initialization); 

我知道用在FLA代碼編碼的髒方法,但我想添加到一個預先存在的遊戲我以前建造的。

+1

這不能是所有的代碼......你需要配合該事件監聽器你的as3類文件..plus的實例不是什麼類文件看起來像 – Ronnie

+0

我發佈了更多的代碼作爲對我自己問題的「答案」。也許它會讓你更好地理解我想要做什麼:/ –

回答

0

一個簡單的解決方案是遷移代碼關閉使用該方法的時間表..

// class file 
public function Main() { 
    //constructor 
    this.addFrameScript(1, frameOneFunc); 
    initialization(); 
} 
private function frameOneFunc(){ 
    This is essentially code in timeline for frame one. 
} 
0

我不完全聽懂你高興,你是說把我的代碼了FLA的,並將其粘貼類文件中的frameOneFunc?

這是一個更多的代碼。

的.fla碼(功能即時試圖運行)在我的類文件

function initialization(); 
{ 
    //random code... 
} 

代碼

public function frame1() 
{ 
    this.savedstuff = SharedObject.getLocal("myStuff"); 
    this.btnSave.addEventListener(MouseEvent.CLICK, this.SaveData); 
    this.btnLoad.addEventListener(MouseEvent.CLICK, this.LoadData); 
    if (this.savedstuff.size > 0) 
    { 
//trying to trigger function here...this is my failed code below 
      //MovieClip(parent).initialization(); 
      //var e:Event = new Event("runFunc",true) 
      //dispatchEvent(e) 
      //dispatchEvent(new Event("initialization")); 
      this.nameField.y = 800 

      this.note.y = 800 

      this.btnSave.y = 800 

      this.btnLoad.y = 800 
      this.tigger.y = 0; 

      trace(this.savedstuff.data.username); 
     this.nameField.text = this.savedstuff.data.username; 
     this.note.gotoAndStop(4); 
    } 
    return; 
} 
+0

爲什麼不從一個類文件運行所有的函數?使用文檔類(屬性面板)設置您的FLA。您應該儘量避免在時間軸上使用代碼。通過本教程真正快速閱讀http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/ – Ronnie

+0

我有大約2000行代碼主要時間表已經。如果可能的話,儘量避免將鱈魚移入類。 :/ –

相關問題