我有兩個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;
}
}
}
}
是否可以鏈接.fla文件和兩個.as文件?如果是這樣,怎麼樣?我去了你的設置的東西,但它不會讓我添加兩個文檔類 – Adzi 2012-03-09 11:20:35
對不起。堆棧溢出回答問題。如果你還沒有弄明白。你只能有一個文檔類。但是在文檔類文件中。您可以導入Reset類,就像導入flash.events。*一樣。你只能從你的文檔類中引用.fla中的命名對象(99%肯定)因此,如果你想在Reset類中使用.fla對象,你必須將它們作爲參數傳遞給函數,或者從文檔類。 – RBalm 2012-06-12 19:48:57
我喜歡閃光,但它有一些粘性的東西。我最大的寵愛就是異步線程模型,我覺得很奇怪,我沒有發現有人抱怨過它。第二次加載任何資源時,您將失去對程序流的跟蹤。除了另外一天,Flash的未來看起來很嚴峻,我想沒有必要讓它磨碎我的裝備。 – RBalm 2012-06-12 19:55:50