Photoshop Tutorials, Flash Tutorials, 3Ds Studio Max Tutorials, Web Design Tutorials |
Home | Submit Tutorial | Top Sites | Free Templates (NEW) | Website templates | Privacy Policy | Link Exchange | Contact Us |
|
Welcome To ProDesignHost.com Flash Tutorials Area - Action ScriptingTaking the First Step I am planning to write a series of tutorials to help with ActionScript. In this first part, I will introduce ActionScripting and try to make clear where to write your code and the scope of your scripts. We will speak about accessing objects at the scene using ActionScript. If any point is unclear for you, please write to me and I will add a comment for this tutorial to make everything more understandable. I think you know what is Flash, how to draw or write something on the scene and how to convert it into a symbol. ActionScript is a programming language which has a syntax very smilar to EcmaScript [or JavaScript] and is the heart of the Flash. By using ActionScript, your Flash movies will become "applications." You will be able to add interactivity to your movies. ActionScript is an easy-to-learn object oriented programming language. It's object oriented but you don't need to declare a class or have any knowledge on objects. You will be able to use built-in objects at the end of this tutorial. Being the first step, we will learn where to write your code in Flash. In Flash, you can write your code 'attached' to keyframes or symbols instances . Select a keyframe or an instance of a symbol at the scene then go to the ActionScript editor. [From now on, you are an 'expert' according to the ActionScript editor and you need to use Expert Mode of the editor.] What you select [a symbol instance or a keyframe] is what your code is attached to. A code that is attached to a keyframe is executed when that frame plays (ie the playhead passes it). If you write your code into [I mean attached to] a keyframe, you can access the symbol instances by using their names only. Lets look at this example:
We named something on the scene, we accessed it and changed a property of it. text property is a property of the textfield object; it carries the inner text of the text box. Before looking at the second place to write the code into (ie attaching code to symbol instances instead of keyframes) lets take a closer look at objects referencing to them. The "dot" Syntax We used a dot (.) in our first example, between the object (myfirsttext) and it's property (text). The dot syntax is very common but I will explain it because I sayed you don't need to know anything about objects. An object in a programming language is like an object in real life. Take your mouse as an example. Lets name it mymouse. Now we can access it's right_button by writing mymouse.right_button. This right button can be clicked by the "method" mymouse.right_button.click(). When we use this method, an event will occur: mymouse.right_button.onClick. Getting this idea will be enough: the leftside of the dot is the owner of the rightside of the dot. Absolute ReferencingIn ActionScript, the master owner of everything in a movie is _root. If you create a symbol instance on the scene, and name it theobject, you can access it from anywhere in the movie typing _root.theobject. If you have the symbol instance (myinstance) on the scene at level 0 (it means the symbol is owned by directly the movie not by another symbol) and in that symbol, you have another (mychildinstance), you can call it _root.myinstance.mychildinstance This is an absolute reference for the object that works from everywhere in the movie. Relative ReferencingIf we want to attach code to a keyframe of mychildinstance object, we can access myinstance object with the keyword: _parent. This keyword makes possible for us to access the owner of where this code is written. We can access another object on the scene named myfirsttext from mychildinstance by using _root.myfirsttext or _parent._parent.myfirsttext. The first _parent is myinstance and the second one means the parent of myinstance, ie _root. You should understand this very well in order to avoid first-step-errors writing your ActionScript code. "this" Keywordthis keyword is used to reference the object's itself. For now, it is enough to learn this. We will use it in function implementations but you don't need to worry about it now. Coding into Symbol Instances You can also write code attached to symbol instances. The code attached to instances consists of event handlers for that symbol instance. If symbol is a button, the instance will be a button object and if it is a movie clip the instance will be a movieClip object. You can use on(name_of_the_event) or onClipEvent(name_of_the_event) event handlers. For example, create a rectangle on the stage and convert it into a movie clip symbol by pressing F8. Select it and write this code into the editor:
Control>>Test Movie and move your mouse over the rectangle. You will see our message in the output window. When you type on ( and wait, a scrollable box will appear that contains the available event names. You may chose from the list or also write it by hand. The code between { } braces will be executed when the event occurs. trace() is a builtin ActionScript function which doesn't have any meanings for the final product. It is used only when authoring to see what the code is doing to find out errors. rollOver is the name of the event when occurs you move your mouse over the object. The difference between on() and onClipEvent() is the types of the events they handles. on() is for button events. I didn't say for button's, be careful; you can use them also with movieClip objects. These events are standart events for buttons, like onRollOver or onRelease (occurs when you click the instance). Movie clip events are used for only with movieClip objects. For example, one of them is load which occurs when a movie clip loads (ie it is downloaded completely) Lastly, summary of what we have learned from this tutorial:
Don't hesitate to comment or write to me. I am waiting for your participation. Author: free2code
|
|
Premium Partners | |||||
|
|||||
Free website templates and paid web templates are great tools to make your websites look perfect! You will save time and money with our flash templates and free website templates
Our visitors are satisfied with the quality of our free and paid website templates! Please visit our free website templates and paid website templates sections. We offer free web templates, free web layouts, free web page templates and other stuff for free download. All templates come with the html and external css file so you may easily edit HTML with your favorite HTML editor. Feel free to download our free web templates for your personal websites. Terms of use depend upon the website template vendor. |
Home | Submit Tutorial | Top Sites | Free Templates | Website templates | Privacy Policy | Contact Us |