在Flash CS5 Actionscript 3中重置媒体文件



我有两个Actionscript文件与一个.fla文件链接。文件Document.as假定支持键盘控件和鼠标控件,而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;
        }

  }
  }
  }

我有两个Actionscript文件与一个.fla文件链接。文件Document.as假定支持键盘控件和鼠标控件,而Reset.as假定控制卡的重置(这是一张交互式生日卡)。我已经在"重置为"文件中添加了这个,但是,当按下"重置"按钮时,什么都不会发生!没有任何图像移动,或任何东西!我是不是做错了什么?所有的文件都被赋予了实例名称!

我没有使用过FlashCS5,但我相信它与CS4相比没有太大变化。你可能错过了几件事。1)您必须确保您的文档文件正确链接到.fla文件。如果链接不正确,Flash IDE会给你一条类似的消息。"在类路径中找不到文档类的定义,因此导出时会在SWF文件中自动生成一个"

Flash项目需要知道在哪里可以找到您的Document.as。转到"文件">"发布设置"在Flash选项卡中,应该有一个区域,上面写着"脚本:",除此之外,还应有一个"设置"按钮。点击设置按钮。在下面的弹出菜单中,您应该会看到一个名为"源路径"的选项卡,在这里添加了您的文档文件在计算机上的目录路径。

2)请确保在.fla中命名了重置对象的实例。在代码中引用它的方法是确保为显示树中的实例应用了名称。你点击对象,在属性部分你可以重命名它。

如果完成了这两件事,您将能够正确地将按钮点击事件注册到您的重置按钮。

最新更新