flash predefined_symbols_types
Types of symbol
During our ActionScript developments we often need to use predefined symbols. A logo, animation or image created in the author environment of Flash can be stored in the library for future use during the application execution.
To convert a graphic object into a symbol, we select it and click F8. The create symbol panel opens:
Three types of symbol are offered:
- Clip
- Button
- Graphic
Bitmaps also exist for symbols but don’t appear here as it is impossible to create a bitmap in this panel.
The clip symbol
Only images imported into the library are integrated as bitmaps.
The clip symbol proves to be the most used in developments so we will start with this and discover the new things brought to it by ActionScript 3.
The clip symbol is without doubt the most used graphic object in Flash animations. If its use hasn’t changed in ActionScript 3, its instantiation and manipulation through programming have been entirely reviewed.
In a new Flash CS3 document we create a clip type symbol which we call Ball. This is added to the library as illustrated here:
By placing an instance of it on the stage we have the possibility of giving it an instance name using the property inspector:
As soon as the instance name is given, Flash adds a property of the same name pointing to the instance on the timeline. The following code allows us to access it:
// displays : [object MovieClip] trace( myBall );
If we define a variable carrying the same name as an instance name, a compilation error is generated indicating a conflict of variables.
This security measure avoids having to define a variable carrying the same name as an instance which in previous versions of ActionScript provoked a replacement of variables which was difficult to debug.
Take the following case: within an ActionScript 1 or 2 Flash animation a clip placed on the stage had the instance name myMc. The following code returns a reference to it:
// displays : _level0.myMc trace( myMc );
If a variable of the same name is defined, the access to our clip is lost:
var myMc:String = "bob"; // displays : bob trace( myMc );
In ActionScript 3 this situation cannot happen thanks to the management of conflicts on compilation. Here we define a variable called myBall on the same timeline as our instance:
var myBall:MovieClip;
The following compilation error is generated:
1151: Conflict in the definition of my myBall in the internal name space.
We will now look at the subtleties in the name property of the flash.display.DisplayObject class. ?
The name property
IIn the article The Display List we saw that the name property of a DisplayObject could be dynamically modified.
Another new thing in ActionScript 3 appears in the manipulation of the name property of symbol instance placed in the author environment of Flash CS3.
In ActionScript 1 and 2 we can dynamically modify the name of a graphic object thanks to the _name property. By doing this we can change the variable at the same time allowing us to target it.
In the following example, a clip had myMc as instance name:
// displays : myMc trace( myMc._name ) ; myMc._name = "myNewName"; // displays : _level0.myNewName trace( myNewName ); // displays : undefined trace( myMc );
In ActionScript 3, it is not possible for symbol instances placed manually on the stage. Only graphic symbols created by development allow for the modification of their name property.
In the following code we try to modify the name property of an instance of a manually placed symbol:
// displays : myBall trace( myBall.name ); myBall.name = "myNewName";
Which generates the following execution error:
Error: Error #2078: Impossible to modify the name property of an object placed on the timeline.
The link in AcionScript 1 and 2 between the _name property and the instance access is no longer valid in ActionScript 3. If we create a Sprite in ActionScript 3 and we give it a name using the name property, no variable of the same name is created to access it:
var mySprite:Sprite = new Sprite; mySprite.name = "myInstanceName"; trace( myInstanceName );
The following compilation error is generated:
1120: Access to the property not defined myInstanceName.
To access it by this name we use the getChildByName method defined by the flash.display.DisplayObjectContainer class.
var mySprite:Sprite = new Sprite; mySprite.name = "myInstanceName"; addChild ( mySprite ); // displays : [object Sprite] trace( getChildByName ("myInstanceName") );
Another new thing in ActionScript 3 concerns the deletion of graphic objects placed using the author environment.
In ActionScript 1 and 2 it was impossible to delete the display of graphic objects. Developers had to use a special method which was to pass the object to a positive depth before calling a method like removeMovieClip.
In ActionScript 3 we can delete all the graphic objects placed manually on the stage using the removeChild method. The following code deletes our instance of the manually placed Ball:
removeChild ( myBall );
So designers are happy to animate instances of symbols manually and a developer would prefer to do it by programming symbols in the library. We will now see how to do this in ActionScript 3.
Worth remembering
- It is possible to modify the *name** property of a graphic object placed manually on the stage.
Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42





