Author : ManMeng
Difficulty : Easy / Medium
Topic : function() in Flash
It's powerful i mind you, and it's even mightier than Thor or Hercules, well, in my
opinion of course, at least it helped me to get through the website I've completed
recently, and saved my a** on a lot of troubles, (http://www.newmediaaward.com/).
Reading this article, I assume that you would have at least a minor knowledge of what
Flash MX / Flash MX 2004 can do for you, generally.
Introduction
It's so powerful that you can't live without it, and it's so dynamic that you are able to 'call' the function from everywhere within the movie, even if your movieclip are hiding
down deep inside the flash file. And what's even more you can put function inside another
function! And you are not even restricted to do all those super-hyper-special-dynamic-
interaction anymore!
But before i begin anything, i would like to seriously salute, bow and thank to Mr.Chee
Yen from HueVisuaLab that at least enlighten me towards this path to function() in flash.
:D. He's a great mentor to me at least.
The Concept
Okay, you'll even notice that the 'trend' are moving towards from what you hear:
-Script-everything-in-one-frame-flash-file
-ActionScript 2.0
-No-need-write-any-on-release-on-button-anymore
-use-alot-of-movieclip-only
Okay, that must scare you away, well, to be honest, REAL HONEST, it's not that freaking
hard to do it, and you'll be amaze and cry until you dry your tear how easy it is to
master all of those above! I did, and so can you!
The Trick
To show you how it works briefly on this article before i move on to another new post that i'll show how you can utilize this cool function() to create awesome navigation effect without even need you to go through the hassle copy pasting million of times.
So to understand the concept is EXTREMELY IMPORTANT.
First, we only need to have 2 layers for the Flash file (I'll provide the link for download at the end of this lesson). Obviously we'll need one layer that stores the Actionscript & function().
And the layer below is a MovieClip that will act as a button.
You ask why? It's my preference and you'll know why later.
To demonstrate how actually this function() will work, let's start by giving the button a name, i'll name it mc_btn. Then proceed to the actions layer, open up your Actions Panel by pressing on your F9 on your keyboard (PC). We'll use Export Mode if you're in Flash MX (Flash MX2004 by default, we'll have to type the script ourselves,but dont worry, it's not that hard as you think it is!), and it'll be easier for me to demonstrate how this thing work.
The ActionScript
No worries, here's the code you'll need to make it work, if you have trouble understanding it, it's the new Flash Event Model, I'll provide a link for you to read some articles about if you're curious, but even if you have no idea what it is about, you can master it easily, weird eh?
//--------------------------------------------------------------
// the function that you will call when user click on it //
function btnClicked() {
trace("hi")
}
// when user click on this button, instead of writing
// on (press) on a button, you can now do it on the frame
// while still getting the same effect
mc_btn.onPress = function() {
btnClicked()
}
//--------------------------------------------------------------
Save the movie and test it! Note that you can replace the trace("hi") with any other action you want flash to perform, using trace() is just for testing purpose and demonstrate how it works.
[Download FLA]
Have fun!
Salutes,
ManMeng
No comments:
Post a Comment