Groups | Blog | Home
all groups > flash actionscript > january 2007 >

flash actionscript : AS 2.0 and class question



Brian
1/29/2007 6:12:09 PM
I put the following, which is for my buttons into an .as document:

this.nav.contact_btn.onRelease = function():Void {
trace("test");
};


When I compile my .fla, it get the following error:

**Error** /Users/brian/Documents/Capitola
Media/Development/Flash/nav.as: Line 3: ActionScript 2.0 class scripts
may only define class or interface constructs.
};


And I guess I don't really get it. Can someone explain this to me, that
would be great!!!

butcho
1/30/2007 4:47:37 AM
Hi,

my first question is how did you link your nav button to the ".as" file? ...
It seem like you link it through the library and if so, your code is not a
declaration of a class. Every class need to be declare as a class or it will
only be some actionScript code in a ".as:" file.

You should try something like this (if you linked the class trough the
library):



import mx.utils.Delegate;

class MyNavBtn extends MovieClip{

// Constructor
function MyNavBtn(){
// as your class is linked trough the library and the class itself
extends MovieClip,
// the keyword "this" represent your nav button
this.onRelease = Delegate.create(this, onNavEvent);
}

private function onNavEvent(){
trace("test : my Nav button has been pressed!");
}
}
butcho
1/30/2007 5:05:38 AM
Me Again,

you may also want to not link your nav button to the class. You can just
instanciate the class and pass as a parameter the nav button (composition). So
on your timeline you instanciate it :

var nav:Navigation = new Navigation(_root.nav.contact_btn);
// note that this way your Navigation Class need to be in the same folder than
your fla file
// if you want to have your class in a sub-folder use this (assuming that the
sub-folder is called "classes"

import classes.Navigation;

var nav:Navigation = new Navigation(_root.nav.contact_btn);

So now the class will go like this:



import mx.utils.Delegate;

class classes.Navigation{

private var contact_btn:MovieClip;

// Constructor
function Navigation(mc:MovieClip){
contact_btn = mc;
//
contact_btn.onRelease = Delegate.create(this, onGetContact);
}

private function onGetContact(){
trace("contact_btn has been pressed! -> path of contact button: " +
contact_btn);
}
}
Brian
1/30/2007 10:03:25 AM
OK,
I think this might be getting more complicated than I wanted to make it.
I just wanted to have the code for my button in an external as
document. Does that mean I have to make it a class? Right now I have two
external as documents.

My main fla has the following AS in it:

stop();
#include "capitola.as"
#include "nav.as"



capitola.as looks like this and just is the opening sequence so far. So
this is not a class, just external .as document.
import com.mosesSupposes.fuse.*

ZigoEngine.register(Fuse,PennerEasing,FuseFMP);

//Initial Opening Sequence of the site
//*************************//
function initialOpenSequence():Void{
trace("openSequence has started");

this.attachMovie("site_frame", "site_frame",
this.getNextHighestDepth(), {_x:0, _y:0, _alpha:0});
this.attachMovie("logo", "logo", this.getNextHighestDepth(), {_x:100,
_y:26, _alpha:0});
this.attachMovie("mainImg", "mainImg", this.getNextHighestDepth(),
{_x:80, _y:90, _alpha:0});
this.attachMovie("line", "line01", this.getNextHighestDepth(), {_x:80,
_y:85, _alpha:0});
this.attachMovie("line", "line02", this.getNextHighestDepth(), {_x:80,
_y:280, _alpha:0});
this.attachMovie("nav", "nav", this.getNextHighestDepth(), {_x:80,
_y:290, _alpha:0});
this.attachMovie("indexText", "indexText", this.getNextHighestDepth(),
{_x:110, _y:375, _alpha:0});


var fOpenSite:Fuse = new Fuse();
fOpenSite.label = "openSequence"; // label is a convenience for
traceItems() calls.
fOpenSite.autoClear = true; // set instance to self-destroy after
completion

fOpenSite.push(
[
{target:site_frame, _alpha:100, seconds:3, ease:"easeOutQuad"},
{delay:1, target:logo, _alpha:100, seconds:1, ease:"easeOutQuad"}
]
);
fOpenSite.push({target:mainImg, _alpha:100, seconds:2,
ease:"easeOutExpo"});
fOpenSite.push({target:line01, _alpha:100, seconds:2, ease:"easeOutExpo"});
fOpenSite.push({target:line02, _alpha:100, seconds:2, ease:"easeOutExpo"});
fOpenSite.push({target:nav, _alpha:100, seconds:2, ease:"easeOutExpo"});
fOpenSite.push({target:indexText, _alpha:100, seconds:2,
ease:"easeOutExpo"});

fOpenSite.start();

}
initialOpenSequence();


function afterFuse():Void{
trace("fuse comlete");
}



Then I have the code for the navigation in nav.as and that is it so far.
this.nav.contact_btn.onRelease = function():Void {
trace("test");
};
this.nav.contact_btn.onRollOver = function():Void {
trace("test");
};
this.nav.contact_btn.onRollOut = function():Void {
trace("test");
};




That is all I have. I was just wondering why I am getting that error
message from the nav.as document?

Thanks for any help!
Brian

LuigiL
1/30/2007 10:13:20 AM
Brian
1/30/2007 1:04:03 PM
LuigiL,
thank you so much!
I was actually really wondering about it, because I commented out the
include for nav.as and was still getting the error.

Thanks,
LuigiL
1/30/2007 6:57:43 PM
[quoted text, click to view]

No, normally you don't.

As strange as it might seem, the error occurs in capitola.as and specifically
the lines:
15. this.attachMovie("nav", "nav", this.getNextHighestDepth(), {_x:80, _y:290,
_alpha:0});
27. fOpenSite.push({target:nav, _alpha:100, seconds:2, ease:"easeOutExpo"});

If you comment those lines, the script validates.

You cannot use the word 'nav' for the linkage identifier of your movieclip and
name your as file nav.as
Rename nav.as to navigation.as and delete nav.as
Then you should be in the clear.
LuigiL
1/31/2007 8:39:05 AM
AddThis Social Bookmark Button