I have a main movie that has the code:
import AS.*;
(The name of my ActionScirpt folder is AS.)
The following script does not seem to be working or loading and I am not sure why. Can anyone help me with this? Anyone know why? Thanks.
package AS
{
public class Initialize extends SimpleButton
{
public function buttonInt()
{
//Next Button Code
next_btn.addEventListener(MouseEvent.CLICK, mouseClickHandler);
//Admin Button;
admin_btn.addEventListener(MouseEvent.CLICK, mouseClickHandler);
}
private function mouseClickHandler($e:MouseEvent):void
{
trace("Clicked the button.");
if (green_mc.currentFrame != 1)
{
green_mc.gotoAndStop(1);
}
if (gray_mc.currentFrame != 1)
{
gray_mc.gotoAndStop(1);
}
gotoAndStop(currentFrame+1);
next_btn.visible = 0;
tomatoCount = 0;
}
}
}
if you import a class file into a frame you need create a instance of the class
var yourClass:Initialize=new Initialize();
to add a class to a file you need type the class path in properties panel
Class path : AS.Initialize
and change your Initialeze file to import all the Classes in the folder
package AS
{
Import AS.*;
public class Initialize extends SimpleButton{
public function buttonInt(){
//Next Button Code
next_btn.addEventListener(MouseEvent.CLICK, mouseClickHandler);
//Admin Button;
admin_btn.addEventListener(MouseEvent.CLICK, mouseClickHandler);
}
privatevate function mouseClickHandler($e:MouseEvent):void{
trace("Clicked the button.");
if (green_mc.currentFrame != 1)
.
.
.
A few things concern me about the code. On a smaller note I'd use reverse domain name notation to name your code, e.g. package com.somedomain.someApp.someClass instead of just AS. It keeps things separated nicely.
Another thing is using the name "Initialize" as a class name. A class name should describe what the class represents. It would be confusing to figure out what "Initialize" actually did just by looking at code.
You also have no public constructor for the button which, while it isn't needed, can be good practice, e.g.:
public function Initialize(upState:DisplayObject = null, overState:DisplayObject = null, downState:DisplayObject = null, hitTestState:DisplayObject = null)
{
this.upState = upState;
this.overState = overState;
this.downState = downState;
this.hitTestState = hitTestState;
super();
}
Lastly you're directly trying to affect a bunch of pre-named elements like green_mc, next_btn, admin_btn, etc. Are you opening library items, exporting for actionscript and are setting their base class to this class? This class will need those items to exist and I don't see any code here creating those items.
North America
Europe, Middle East and Africa
Asia Pacific