What is the Macromedia Flash Actionscript dot syntax and how do i use it?
In Macromedia Flash there are multiple ways how you can setup your actionscript code.
One of those ways is to place your codes onto an object like a movieClip or button etc..
An example of this could be:
Draw a square
Select it, press f8
Give it "square" as a name and make sure you export it for actionscript in the advanced options.
This is really important because now actionscript needs to indentify your object to be able
to do something with it. By giving it a linkage and exporting for actionscript, actionscript will know
how to indentify the object and you can instruct actionscript to use it.
Then convert it into a movieClip by pressing ok.
Select it again now its a movieClip and press f9 to open the code editor.
Now one could attach some code like for example this:
on(press){
trace("hello reader, this is not a good way to setup your code");
}
As you noticed this actually places code onto the object, and that is also why i personally wont ever use it.
When you start making a habbit of working like this and creating objects all over your document then its
just a matter of time ( and not that much) and you will start running into trouble. You will get into trouble because
without a doubt you will have to debug your code after you run it, there is no hiding from that.
If you place code on all kinds of objects all over your document then you will loose increddible amounts of time
searching where things are going wrong and where you had placed that little piece of code that messes things up.
You will stress your hands a lot more by having to click through all your clips
and search through all your timelines for that evil bit of code. In other words, its a "Debugging Hell"!
The Actionscript dot-syntax to the resque
Even though other people might still swear by using the way of coding i described above,
i swear by using the dot syntax. So lets take the square example again to highlight the major
difference between the two.
Draw a square again
Select it, press f8
Give it "squareDotSyn" as a name and make sure you export it for actionscript in the advanced options.
This is really important because now actionscript needs to indentify your object to be able
to do something with it. By giving it a linkage and exporting for actionscript, actionscript will know
how to indentify the object and you can instruct actionscript to use it.
Then convert it into a movieClip by pressing ok.
Now here comes the difference, this time dont select the square but create a new layer and call it "code".
Select the first frame of this newly created layer and press f9, the code editor pops up and you will have to
input this code:
squareDotSyn.onPress = function(){
trace("this is the way code should be setup, its way better");
}
Remember that we had setup a linkage name "square", here you saw how we instructed actionscript to use this object
and attach an onPress event to it. Everytime this object is pressed the text is outputted. ( when run inside flash)
Perhaps you dont see the major advantage at this point yet, but i will guarantee you that if you are starting to write
more complex pieces of code, you cant thank yourself enough for having learned using the dot-syntax.
Now you can address every object in your flash file from right here as long as you have setup a linkage name for each object you
want to use. So perhaps we had a clip inside another clip on stage and we would want to setup some rollOver for this
clip thats inside the other one. We could easilly do that by doing something like this:
Now if we had used the "placing code on objects way", then we would have had to physically enter the parent
clip on stage and attach codes to the child clip. If we then would want to change a bit of code, we would have to search
for this code all over again in our document and change it etc... This is a huge pain in the butt.
It might not seem to be big problem in a small document like this, but in a big document with loads of clips etc..
it will make a huge difference.
Conclusion
If you learn to use the dot-syntax you will develop a feeling for bigger codes and a cross over to something like using PHP
wont we as big of a problem as it might be when you are used to never using the dot-syntax.
Or making things like a game will be a lot more easilly accomplished by using this better way of setting up your actionscript.
Eventhough the dot-syntax seems to execute a fraction slower then that placing code directly onto objects,
this minor difference is neglectable if you think about the huge difference in code usability.
I hope i have convinced you of how useful it is to use the dot-syntax with this small example. If you are happy
with placing codes all over the place you should do that, but personally i really feel strongly that you are hurting your
self by doing that. There is however an exception for really really small Flash documents, but even then i feel you are
better off using the dot-syntax. Your codes will grow to a more professional level thats a sure thing.
Comments
5 comment(s) found in 1 page
viewing comment(s): 1 - 5
1 |
27-09-07:paul
oh wow
24-07-07:guest
what is dot in macromedia flash
26-11-06:m
mhm nice
11-04-06:dude
15-10-05:guest
- Press here to view all available smilies!