Flash9:ActionScript 2.0:Import and visibility
|Flash11 (CS5) | Flash10 (CS4) | Flash9 (CS3) <|
|Table of contents|
By the end of this exercises you should be able to:
Create a new Flash movie and add assets
1. Create a new Flash File (ActionScript 2.0)
2. Copy the following files as Btn1.png and Btn2.png to the folder you are creating the movie in (right click and save the images)
3. Use File > Import > Import to Library, and import both Btn1.png and Btn2.png. In the Library will be placed both the image (png) and a Symbol
Add assets to stage
4. Drag both symbols to the stage, and change the type from Graphic to Movie Clip. This will allow you to name the instances.
5. Under the Movie Clip text box Name the instances as mcBtn1 and mcBtn2
6. Add a button from the Window > Common Libraries > Buttons selection and drag onto the stage (I have used Buttons tube double | tube double blue)
Add Action Script
7. Finally add this ActionScript to the button, (Click on the button and press F9, then in ActionScript 1.0 & 2.0 > Movie Clip Control > on ...)
- Make sure the if and else are LOWERCASE
- Check that the images are Movie clips
- check that the names given to the instances are exactly the same as those in the code (includes upper and lower case letters)
Making an object Visible
Keeping track of the number of times an event occurs, and then when the required number of actions have taken place, making an object visible adds another dimension. For example, we have a series of aircraft components, wings, wheels etc that need to be dragged and dropped on to the correct plane. Once the correct fuselage, wheels and wings are all lined up, the aircraft changes into a coloured version of its former monotone self.
Here's the code:
One frame one of the movie, you will need to set the initial visibility state of the coloured object, plus a variable for keeping count. In this example there are six different aircraft requiring construction:
For each aircraft wing and wheels that need to be dragged and dropped and locked into place, use the following code, changing the instance naming as required:
Ok, so what we have here is:
- Actionscript to drag and drop
- if statement to check to condition of the dropped component and if it matches the target zone
- Increment the counter
- If the counter == 2 (ie two pieces dropped and locked) the coloured object will now become visible, and all others visibility set to false.
Copy and paste the Actionscript onto each draggable object, change the naming of the object and targets to match.
HOT TIP! Dont forget to double check all the naming for case or missing bits - usually the cause of any problems with this sort of exercise and watch things like forgetting the underscore when referring to root objects and visibility (Very Important!)