A primary building block of any scripting or programming language is a subroutine. A subroutine is any set of code that you wish to reserve for a specific task. A subroutine is useful for code that you wish to reuse in multiple event handlers (for example, Button instances and keyframes). In Flash ActionScript, subroutines are called functions, and are created with the function action.
What functions do
A function (or subroutine) sets aside a block of code that can be executed with just one line of code. Functions can execute several actions, and pass options (called arguments) to those actions. All functions must have a unique name, so that we know what to reference in later lines of code. In a way, functions are equivalent to your own custom additions to the Flash ActionScript language. In Flash 4, we used the call action to execute code blocks located on other keyframes in the Flash movie. In Flash 5, we can define a function on a specific timeline, and refer to its path and name to execute it.
When to create a function
For people new to scripting, perhaps the most confusing aspect of functions is knowing when to create them in a Flash movie. Use the following guidelines to help you determine when a function should be created:
How to define a function
When you add a function to a keyframe on the Main Timeline or a Movie Clip timeline, you are defining the function. All functions have a target path, just like other Objects in Flash. All functions need a name followed by opening and closing parentheses, but arguments (options to pass to the function) inside the parentheses are optional.
As a simple example, let’s say you wanted to create a function that has one goto AndStop() action. This function will have a shorter name than gotoAndStop(), and will be faster to type and use in our ActionScript code. We’ll place this on the first keyframe of our Main Timeline.
This function, when evoked, will send the Main Timeline playhead to the start label We could further expand the functionality of gts() by adding an argument, which we’ll call frameLabel:
In this version of the gts() function, instead of hard-coding a frame label such as start into the actual gotoAndStop() action, we specify an argument with the name frameLabel. Just like variable names, the names of your function and its arguments are entirely up to you—the name frameLabel has no significance. Flash simply knows that if we pass an argument to the gts() function, that it should place that argument where the frameLabel term occurs in our actions. An argument acts as a placeholder for information that will be supplied to the function on a per-use basis; that is, we can specify a different value for frameLabel each time we evoke the gts() function.
How to execute a function
After you have defined a function on a timeline’s keyframe, you can create actions that refer to the function’s actions. The standard method for executing a function is:
At the end of the previous section, we defined a function named gts() on the Main Timeline. If we added a Button instance to our movie, we could then execute the function from the Button instance with the following code:
When this Button instance is clicked, then the function gts() on the _root timeline (the Main Timeline) is executed, and passed the argument “start”. In our function gts(), we defined frameLabel as an argument that occurs in the gotoAndStop() action. Therefore, the Main Timeline will go to and stop on the “start” frame label. Later , we use functions to create a dynamic reusable menu system in a Flash movie.
Flash Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Adobe Flex 3 Interview Questions||Dreamweaver Interview Questions|
|3D Animation Interview Questions||Adobe Flash CS6 Interview Questions|
|Dreamweaver CS3 Interview Questions||Adobe Flex Interview Questions|
|Adobe Flex Actionscript Interview Questions||Gif Animation Interview Questions|
|Adobe Fireworks Interview Questions|
Understanding The Flash Framework
Exploring The Interface: Panels, Settings, And More
Using Tools For Navigation And Viewing
Working With Selections And The Pen Tool
Working With The Drawing And Painting Tools
Working With Text
Exploring The Timeline
Checking Out The Library: Symbols And Instances
Drawing In Flash
Animating In Flash
Using Bitmaps And Other Media With Flash
Designing Interfaces And Interface Elements
Understanding Sound For Flash
Importing And Editing Sounds In Flash
Optimizing Flash Sound For Export
Understanding Actions And Event Handlers
Navigating Flash Timelines
Controlling Movie Clips
Sharing And Loading Assets
Planning Code Structures
Creating Subroutines And Manipulating Data
Understanding Movie Clips As Complex Objects
Sending Data In And Out Of Flash
Understanding Html And Text Field Functions In Flash
What Is Generator?
Revving Up Generator
Working With Third-party, Server-side Applications
Working With Raster Graphics
Working With Vector Graphics
Working With Audio Applications
Working With 3d Graphics
Working With Quicktime
Working With Realplayer
Creating Full-motion Video With Flash
Creating Cartoon Animation With Flash
Planning Flash Production With Flowcharting Software
Working With Authoring Applications
Publishing Flash Movies
Integrating Flash Content With Html
Using Players, Projectors, And Screensaver Utilities
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.