2012-12-07 37 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行代码主要时间表已经。如果可能的话,尽量避免将鳕鱼移入类。 :/ –

相关问题