Home / Tutorials / Components / Build a Flash component (Flash MX 2004 to Flash CS3) - Part 1 /

Flash Tutorials

Build a Flash component (Flash MX 2004 to Flash CS3) - Part 1 - Preparing your future component - Add the ActionScript code

Posted by : Flashtuning on Nov 07, 2007

 

5.0/5

Check also other great FlashTuning.net products by clicking the image below:

The goal of this chapter is to get a closer look at few general ActionScript code lines necessary for your future component . All the code in this FLA is placed inside the first frame of the component_mc_simulation Movie Clip on the stage.

1. First declare variables, corresponding to the Progress Bar slider Movie Clips from the library (the left thumb, the resizible middle symbol and the right thumb) like in the following image:

The __slider Movie Clip will contain the __sliderLeftThumb and __sliderBar and __sliderRightThumb and sliderBarMask.

2. Declare variables corresponding to the Progress Bar track Movie Clips from the library (the left track thumb, the middle portion and the right thumb) like in the following image:

The __track Movie Clip will contain the __trackLeftThumb and __trackBar and __trackRightThumb.

3. Declare variables for the bytes loaded, bytes total and percentage, like in the following image:

4. Create a function having the component name (this function is known as "constructor" in your future component class and is required). For this example the function name is MyProgressBar(), like in the following image:

5. The init() function will be used for global parameters initialiation:

6. The createChildren() method is used to attach all the symbols from the library to their corresponding Movie Clips variables previously declared. The following image is just a preview. You can check the complete source code inside the BasicFlaStructure_01.fla file available for download.

7. The arrange() method (also known as draw() or you can give it your own suggestive name). This method handles the visual content positioning based on various actions (e.g: if you will adjust the width of your component either on the stage or via a function call, you have to also place a call to the arrange() function to adjust the layout). You can check a preview of this method in the image below:

8. The four methods previously declared: MyProgressBar(), init(), createChildren() and arrange() represents for now the core functions of your future component.

9. Other methods are: startPreloadingEngine(), stopPreloadingEngine(), checkPreloading(), getProgress() and setProgressBar(). You find each method and adjacent comments in the FLA file.

10. In the next tutorial (Build a Flash component - Part 2) you will find the necessary steps to achieve a SWC (component) file starting from your FLA file (the steps presented for the component creation are available when creating a component for Flash Mx2004 to Flash CS3, ActionScript 2.0. For Flash CS3, ActionScript 3.0 the general steps are the same only the syntax is different. We will convert your progress bar AS 2.0 component to AS 3.0 component in the Build a Flash component - Part 3 tutorial).

12. DOWNLOAD THE SOURCE FLA FOR THIS TUTORIAL

Check also other great FlashTuning.net products by clicking the image below:

no comment

Add comment

Please login to post comments.