i was wondering where you put the a/s, in the layer or on the object. Whats the diffence to put a/s in the layer or on the object?
It depends completely on the AS and where it was meant to be put.
It doesn’t really matter anymore. Now that you can give instance names to pretty much anything in Flash, it’s better to have layers of code, and nothing on the objects. That way, you can have a look at the entire code, and you’re sure you’re not forgetting anything you might have put on your objects. But it’s a matter of preference, really.
pom
Maybe for most people, but I’m a fan of the “this” object hehe.
And what does stop you from using it when coding on a layer?
I always code in external as files and use the ‘this’ object all the time!
hehe?
I don’t think I can take code from a MC with something like this:
[AS]
onClipEvent(enterFrame) {
this._x += 5;
}
[/AS]
and put it on the layer… Unless I go through the entire code and change all the references to “this.” I guess that wouldn’t be that hard after all…
And why don’t u use:
[AS]
myMovieClip.onEnterFrame = function(){
trace("this: "+this);
this._x += 5;
}
[/AS]
or even better:
[AS]
myMovieClip.myParent = this;
myMovieClip.onEnterFrame = function(){
trace("this: "+this+ "this.myParent: "+this.myParent);
this._x += 5;
this.myParent._y -=5;
}
[/AS]
to have access at the same time to both myMovieClip and its parent regardless of where the MC sits
I always code on timelines. Makes the use of variables so much easier. And, the double scope is very handy too :thumb:
Originally posted by eki
**or even better:
myMovieClip.myParent = this;
myMovieClip.onEnterFrame = function(){
trace("this: "+this+ "this.myParent: "+this.myParent);
this._x += 5;
this.myParent._y -=5;
}[/AS]
to have access at the same time to both myMovieClip and its parent regardless of where the MC sits**
... Don't you have the [[font=courier new]_parent[/font]](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary561.html) property already!? :sigh:
:P
How do you do external AS files?
Make a file with extension .as and do a #include myfile.as in your movie? Can you put all your script into an external file then just include it? Are there any tutorials regarding this? I tried searching the forums for info on it, but couldnt really find a satisfying answer.
http://www.kirupa.com/developer/actionscript/tricks/include.htm
Voetsjoeba >> Double scope? What do you mean?
Kode >> That’s a good question