Functions can also be used with the new constructor to create objects with properties and methods assigned by the function. This means that you can use a function to create unique objects, based on parameters that you pass as arguments to the function upon invocation. In this section, we deconstruct another function example that creates an entire Sound Library with ActionScript, without using any Movie Clip instances.
Open your copy of the soundObjects.fla file in Flash 5. You’ll notice that there aren’t any Movie Clips and/or physical elements on the Stage. Double-click the first (and only) frame on the actions layer. In the Actions Panel, you’ll see the following code:
There are three sections to this code: the function definition; the object creation and assignment; and the method execution of the Sound Objects.
The createLib function has two arguments: start and end. Again, these are userdefined function names and arguments. You could rename the function and arguments to your own preferred terms. The for loop in the createLib function will create a snd array object within the calling object (this). This array will contain Sound Objects that use the .AIFF sound files in the Library. Note that each of the sounds in the Library have been set to export with the .SWF file, as defined by the Linkage Properties for each sound.
Object creation and assignment
After the createLib function is defined, we can use it for new objects. In our example, a new object named soundLib is created after the function definition:
First, the object is declared as being on the this timeline. This enables us to load this Flash movie into other Flash movies and retain proper targeting paths for the createLib function. If you test this movie on its own, this will simply be equal to _root or _level0. Using the new constructor, we create the snd array and Sound Objects relative to the soundLib object. We are creating a unique object with specific properties and values. This enables you to make as many objects as you desire, all from one function:
These actions (not used in our example) would create two separate soundLib objects, each using a specific range of Sound Objects from the Library.
The numbers specified in the parentheses indicate the sounds to use from the Library. Remember that in our function createLib, the start and end arguments are used to form the linkage identifiers:“sound_”+i
where i is defined by the start argument, and incremented until the end argument value is reached.
Sound Object method execution
Finally, after the Sound Objects are created within the soundLib object, we can play the sounds with the Flash 5 built-in start method for Sound Objects:
These lines of code tell the Sound Objects located in the 1 and 2 index positions of the snd array (for example, sound_1 and sound_2 from the Library) to play. This is just one example of using functions to create new objects. You can use functions to create other types of data-based objects for record storage and retrieval, as well as to create unique Color Objects to reference with more than one Movie Clip target.
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.