I’ve got two Actionscript files linked with one .fla file. The file Document.as is suppose to support the keyboard controls and the mouse controls, whilst the Reset.as is suppose to control the reset of the card (this is an interactive birthday card). I’ve added this on the ‘Reset.as’ file, however, when the “reset” button is pressed, nothing happens! None of the images move away, or anything! Am I doing something wrong here? All the files have been given instance names!
Here is the ‘Reset.as’ code;
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;
}
}
}
}
I’ve got two Actionscript files linked with one .fla file. The file Document.as is suppose to support the keyboard controls and the mouse controls, whilst the Reset.as is suppose to control the reset of the card (this is an interactive birthday card). I’ve added this on the ‘Reset.as’ file, however, when the “reset” button is pressed, nothing happens! None of the images move away, or anything! Am I doing something wrong here? All the files have been given instance names!
I haven’t used FlashCS5 but I’m sure it hasn’t changed much from CS4.
There could be a couple of things you missed.
1)
You have to make sure that your Document file is linked properly to your .fla file.
If it isn’t linked correctly, the Flash IDE will give you a message of the sort.
“A definition for the document class could not be found in the classpath, so one will be automatically generated in the SWF file upon export”
The Flash project needs to know where to find your Document.as.
Go to File > Publish Settings
In the Flash tab, there should be an area that says “Script:” and besides it there should be a “settings” button. Hit the settings button.
In the following popup menu you should see a tab called “Source Path” here added the directory path to where your document file is located on your computer.
2)
Make sure you named the instance of your reset object in your .fla. The way to reference it in your code is to make sure you applied a name to the instance that is one the display tree. You click on the object an in the properties section you can rename it.
If these two things are done, you will be able to properly register the button click event to you reset button.