We’ve already discussed functions as subroutine mechanisms in Flash movies. Functions can be used to define a set of actions that are later executed when the function is invoked. In Flash 5, you can use also functions as methods of other code objects. Methods are actions specific to actions. Unlike properties and values, methods carry out a task with that object. In this section, we deconstruct a .FLA file that uses a function to create a menu completely from ActionScript.
Open a local copy of the createMenu.fla file in Flash 5. You’ll notice that the Main Timeline has a setup similar to the arrayMenu.fla file that was discussed in the last section. We have a series of labels, indicating sections of the Flash movie. If you test this Flash movie, you’ll see a dynamic menu display. Clicking each button takes you to the corresponding section of the Flash movie.
Unlike our previous arrayMenu.fla example, though, notice that we have different text on the menu buttons than the text used in the frame labels. For example, the Our Products menu button takes you to the products label on the Main Timeline.
For this Flash movie, a function with multiple arguments enables you to specify the text of the menu buttons separately from the targeted labels (and timelines).
Double-click the first frame of the functions layer. In the Actions Panel, you’ll see this function appear in the Actions list (note that the ¬ indicates a continuation of the same line of code; this character does not appear in the actual code):
The createMenu() function has three arguments: names, targets, and labels. The value for these arguments will be supplied as a method of a Movie Clip instance when the function is executed. Similar to our previous arrayMenu.fla example, we will use arrays to store the values of our frame labels (and section names). However, we’ll also create an argument (and array) to store the button text that will appear on the menu buttons. In this way, we can create ActionScript that correctly uses frame labels in other Go To actions, without worrying about the text that is actually used as a button item. The targets argument is used to create an array of timeline targets for each button item.
The function also uses the attachMovie method (instead of duplicateMovieClip) to use the menuItem Movie Clip symbol in the instance timeline executing the function. In our example, there is a menu Movie Clip instance on the Stage. This empty Movie Clip instance is assigned the createMenu() function as a method, just as duplicateMovieClip or attachMovie is a method of the Movie Clip object:_root.menu.createMenu = createMenu;
This line of code creates a new method called createMenu, specifically for the menu instance (object) on the Stage. It also set this method to use the function createMenu as its value. Therefore, whenever we evoke the createMenu method of the menu object, the actions within the createMenu function will run.
Note that you can use any method name you prefer—it need not match the name of the function as our example does. So, you could write:_root.menu.customMenu = createMenu;
The function createMenu also uses the this syntax to make the function work in relation to the object that is executing it. this will equal _root.menu for the method assignment, _root.menu.createMenu = createMenu. However, if we had another menu instance, such as menu_2, that used the createMenu function as a method, then this would refer to its path for its method. Herein lies the power of a function as a method of an object you can assign the same function (and arguments) to unique objects (or Movie Clip instances) on the Stage.
To execute the method createMenu for the menu instance, you need to specify the method and any arguments you will supply the method. In our example, the following line (note that the ¬ indicates a continuation of the same line of code; this character does not appear in the actual code) executes the createMenu method for the menu instance:_root.menu.createMenu(“Home,Our Products,Our ¬ Services”,”_root,_root,_root”,”main,products,services”);
In this line of code, the following arguments are passed to the createMenu function arguments:
When the createMenu method is evoked, the createMenu function parses this argument into the actions contained with the function. The split method (for String Objects) takes the values of names, targets, and labels, and makes each commadelimited item (item separated by a comma) into a separate array element:
While you will never see those lines of code in the function, you will see references to these array items. this.itemName[i-1] is used to take each itemName element and put it on the proper menuItem Movie Clip instance in the menu object. The itemTarget array is used to let the menuItem instances know to which timeline target to address the gotoAndStop() action (contained on the Button instance within the menuItem symbol in the Library). The frameLabel array assigns the proper frame label for the gotoAndStop() action for the Button instance. This movie also uses a resetMenu function (and method) to delete the menuItem instances and arrays.
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.