2012-03-09 39 views
0

我有兩個Actionscript文件鏈接到一個.fla文件。文件Document.as假設支持鍵盤控制和鼠標控制,而Reset.as則假設控制卡的重置(這是一張交互式生日卡)。我在'Reset.as'文件中添加了這個,但是,當按下「重置」按鈕時,沒有任何反應!沒有任何圖像移開,或任何東西!我在這裏做錯了什麼?所有的文件都被賦予實例名稱!在Flash CS5 Actionscript 3中重置媒體文件?

這裏是'Reset.as'代碼;

package src 
    { 

import flash.events.*; 
import flash.display.*; 

    public class Reset extends MovieClip 
    {  

     public function Reset() 
    { 

     mouse(); 
    } 

    public function mouse() 
    { 
     reset.addEventListener(MouseEvent.CLICK, Reset1); 
    } 

    public function Reset1(e:MouseEvent) :void 

     { 
      aldo.x = -176.80; 
      aldo.y = 282; 

      aldoo.x = -322.80; 
      aldoo.y = 286; 

      reset.x = -401.75; 
      reset.y = 328.45; 

      firework1.x = 100.75; 
      firework1.y = 545.15; 

      firework.x = 457.55; 
      firework.y = 551; 

      instruction.x = 437.25; 
      instruction.y = 379; 

      fade2.x = 132.15; 
      fade2.y = 433.15 
     } 
    } 
     } 

     //and here's the 'Document.as' code; 


    package src 
    { 
import flash.events.*; 
import flash.display.*; 

public class Document extends MovieClip 
{ 
    var speed:int = 20; 
    var fader:Number = 0.1 

    public function Document() 
    { 
     init(); 

    } 

    public function init() 
    { 
     button1.addEventListener(MouseEvent.CLICK, onMouseClick);   
     stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); 
    } 

    public function onMouseClick(e:MouseEvent) :void 
    { 
     //if cake is clicked, the y axis for instance "instruction", "firework1", "firework" changes           
     instruction.y = 500; 
     firework1.y = 100; 
     firework.y = 100; 

     //if cake is clicked, the y axis for instance "fade2" changes         
     fade2.y = 240;  

    } 

    public function onKeyDown(e:KeyboardEvent):void 
    { 
    //if the right key (arrow key) is pressed, 
    //the instances "aldo and "aldoo" move positively on the x axis by "5" 
    //the instance "fade2" (which is "Press and hold the right key") also fades out 
    //the longer the right arrow key is pressed 
    if (e.keyCode == 39 && alpha > 0 ) 
     { 
      aldo.x += speed; 
      aldoo.x += speed; 
      reset.x += speed; 
      fade2.alpha -= fader; 
     } 

    //if the left key (arrow key) is pressed, 
    //the instances "aldo and "aldoo" move negatively on the x axis by "5" 
     if (e.keyCode == 37) 
     { 
      aldo.x -= speed; 
      aldoo.x -= speed; 
      reset.x -= speed; 

     } 



    } 
    } 
    } 

回答

0

我有兩個Actionscript文件鏈接到一個.fla文件。文件Document.as假設支持鍵盤控制和鼠標控制,而Reset.as則假設控制卡的重置(這是一張交互式生日卡)。我在'Reset.as'文件中添加了這個,但是,當按下「重置」按鈕時,沒有任何反應!沒有任何圖像移開,或任何東西!我在這裏做錯了什麼?所有的文件都被賦予實例名稱!

我還沒有使用FlashCS5,但我確定它沒有多大改變CS4。 可能有一些你錯過的東西。 1) 您必須確保您的文檔文件已正確鏈接到.fla文件。 如果鏈接不正確,Flash IDE會給你一個排序信息。 「無法在類路徑中找到文檔類的定義,因此在導出時將自動生成SWF文件中的一個定義」

Flash項目需要知道在哪裏可以找到您的Document.as。 轉到文件>發佈設置 在Flash選項卡中,應該有一個區域顯示「Script:」,除此之外還應該有一個「設置」按鈕。點擊設置按鈕。 在下面的彈出菜單中,您應該看到一個名爲「源路徑」的選項卡,此處添加目錄路徑,指向您的文檔文件在計算機上的位置。

2) 確保您在.fla中將重置對象的實例命名爲.fla。在您的代碼中引用它的方式是確保您將名稱應用於顯示樹中的實例。您可以單擊屬性部分中的對象並將其重命名。

如果這兩件事情都完成了,您將能夠正確地註冊按鈕點擊事件給你重置按鈕。

+0

是否可以鏈接.fla文件和兩個.as文件?如果是這樣,怎麼樣?我去了你的設置的東西,但它不會讓我添加兩個文檔類 – Adzi 2012-03-09 11:20:35

+0

對不起。堆棧溢出回答問題。如果你還沒有弄明白。你只能有一個文檔類。但是在文檔類文件中。您可以導入Reset類,就像導入flash.events。*一樣。你只能從你的文檔類中引用.fla中的命名對象(99%肯定)因此,如果你想在Reset類中使用.fla對象,你必須將它們作爲參數傳遞給函數,或者從文檔類。 – RBalm 2012-06-12 19:48:57

+0

我喜歡閃光,但它有一些粘性的東西。我最大的寵愛就是異步線程模型,我覺得很奇怪,我沒有發現有人抱怨過它。第二次加載任何資源時,您將失去對程序流的跟蹤。除了另外一天,Flash的未來看起來很嚴峻,我想沒有必要讓它磨碎我的裝備。 – RBalm 2012-06-12 19:55:50