ActionScript 3 interactive objects tutorial (CS3): Difference between revisions
m (using an external editor) |
m (using an external editor) |
||
Line 36: | Line 36: | ||
*# [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/InteractiveObject.html InteractiveObject] | *# [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/InteractiveObject.html InteractiveObject] | ||
*## [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html DisplayObjectContainer] | *## [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html DisplayObjectContainer] | ||
*### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html Loader] | *### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html Loader]: Class for loading objects (Bitmaps, AS3 Sprites or Movieclips, or AS 1/2 AVM1Movie). | ||
*### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html Sprite] | *### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html Sprite]: Manipulable container of objects | ||
*#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlayback.html FLVPlayback] FLVPlayback] | *#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlayback.html FLVPlayback] FLVPlayback] | ||
*#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlaybackCaptioning.html FLVPlaybackCaptioning] | *#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlaybackCaptioning.html FLVPlaybackCaptioning] | ||
*#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html MovieClip] | *#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html MovieClip]: refers to a movie clip symbol created in the Flash authoring tool. | ||
*#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/core/UIComponent.html UIComponent] | *#### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/core/UIComponent.html UIComponent] | ||
*##### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/BaseButton.html BaseButton] | *##### [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/BaseButton.html BaseButton] | ||
Line 58: | Line 58: | ||
*## [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/SimpleButton.html SimpleButton] | *## [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/SimpleButton.html SimpleButton] | ||
*## [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html TextField] | *## [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html TextField] | ||
*# | *# AVM1Movie | ||
*# Bitmap: for displaying a bitmap image | |||
*# MorphShape: | |||
*# Shape: on-screen canvas for drawing content | |||
*# StaticText: Frozen text | |||
*# Video: contains video | |||
== The display list == | |||
At at given time in your animation, your Flash application contains a hierarchy of displayed objects: the '''display list'''. It contains all the visible elements and they fall in one of the following categories: | |||
* '''The stage''': Each application has one stage object and it contains all on-screen display objects (i.e. containers or simple objects). This includes objects that the user can't see (e.g. ones that are outside of the stage). | |||
* '''Display object containers''', i.e. objects that can both simple display objects and display object containers. | |||
* (Simple) ''' display objects''' | |||
== Manipulating objects == | |||
The principle of (simple) object manipulation is fairly simple: change the property | |||
of an object. | |||
=== Simple repositioning example === | |||
<pre> | |||
black_cat.addEventListener(MouseEvent.CLICK, moveCat); | |||
function moveCat(event:MouseEvent):void { | |||
black_cat.x = 100; | |||
black_cat.y = 100; | |||
} | |||
</pre> | |||
=== Change size === | |||
<pre> | |||
blue_cat.addEventListener(MouseEvent.MOUSE_DOWN, resizeCat); | |||
function resizeCat(event:MouseEvent):void { | |||
blue_cat.width = blue_cat.width * 2; | |||
blue_cat.height = blue_cat.height * 2; | |||
} | |||
blue_cat.addEventListener(MouseEvent.MOUSE_UP, resizeCat2); | |||
function resizeCat2(event:MouseEvent):void { | |||
blue_cat.width = blue_cat.width / 2; | |||
blue_cat.height = blue_cat.height / 2; | |||
} | |||
</pre> | |||
=== Let the user drag example === | |||
<pre> | |||
red_cat.addEventListener(MouseEvent.MOUSE_DOWN, startDragging); | |||
red_cat.addEventListener(MouseEvent.MOUSE_UP, stopDragging); | |||
function startDragging(event:MouseEvent):void | |||
{ | |||
red_cat.startDrag(); | |||
} | |||
function stopDragging(event:MouseEvent):void | |||
{ | |||
red_cat.stopDrag(); | |||
} | |||
</pre> | |||
== Links == | == Links == |
Revision as of 14:32, 20 September 2007
This article or section is currently under construction
In principle, someone is working on it and there should be a better version in a not so distant future.
If you want to modify this page, please discuss it with the person working on it (see the "history")
Overview
- Learning goals
- Learn about the most important interactive ActionScript 3 objects
- Learn some methods and properties you may want to use in your animations.
- Prerequisites
- Flash CS3 desktop tutorial
- Flash drawing tutorial
- Flash button tutorial
- Flash components tutorial
- ActionScript 3 event handling tutorial
- Moving on
- ActionScript 3 interactive objects tutorial
- The Flash article has a list of other tutorials.
- Quality
- This text should technical people get going and may not be good enough for self-learning beginners. It can be used as handout in a "hands-on" class. That is what Daniel K. Schneider made it for...
- Level
- It aims at Flash design beginners, not beginning ActionScript 3 programmers, although programmers can read this to get a quick overview before digging into a real documentation like Adobe's Flash 9 reference manual
- Learning materials
Grab the various *.fla files from here:
Interactive objects - an overview
The ActionScript 3.0 flash.display package defines a whole lot of different kinds of visual objects that can appear in the Flash Player.
Below is summary table of ActionScript 3 interactive display objects. It shows that interactive objects are defined as hierarchical classes. Methods and properties that work for a parent class (e.g. Sprite) also will work for its child classes (e.g. UIComponent). Links point to the technical reference manual at Adobe.
- DisplayObject
- InteractiveObject
- DisplayObjectContainer
- Loader: Class for loading objects (Bitmaps, AS3 Sprites or Movieclips, or AS 1/2 AVM1Movie).
- Sprite: Manipulable container of objects
- FLVPlayback FLVPlayback]
- FLVPlaybackCaptioning
- MovieClip: refers to a movie clip symbol created in the Flash authoring tool.
- UIComponent
- Stage
- SimpleButton
- TextField
- DisplayObjectContainer
- AVM1Movie
- Bitmap: for displaying a bitmap image
- MorphShape:
- Shape: on-screen canvas for drawing content
- StaticText: Frozen text
- Video: contains video
- InteractiveObject
The display list
At at given time in your animation, your Flash application contains a hierarchy of displayed objects: the display list. It contains all the visible elements and they fall in one of the following categories:
- The stage: Each application has one stage object and it contains all on-screen display objects (i.e. containers or simple objects). This includes objects that the user can't see (e.g. ones that are outside of the stage).
- Display object containers, i.e. objects that can both simple display objects and display object containers.
- (Simple) display objects
Manipulating objects
The principle of (simple) object manipulation is fairly simple: change the property of an object.
Simple repositioning example
black_cat.addEventListener(MouseEvent.CLICK, moveCat); function moveCat(event:MouseEvent):void { black_cat.x = 100; black_cat.y = 100; }
Change size
blue_cat.addEventListener(MouseEvent.MOUSE_DOWN, resizeCat); function resizeCat(event:MouseEvent):void { blue_cat.width = blue_cat.width * 2; blue_cat.height = blue_cat.height * 2; } blue_cat.addEventListener(MouseEvent.MOUSE_UP, resizeCat2); function resizeCat2(event:MouseEvent):void { blue_cat.width = blue_cat.width / 2; blue_cat.height = blue_cat.height / 2; }
Let the user drag example
red_cat.addEventListener(MouseEvent.MOUSE_DOWN, startDragging); red_cat.addEventListener(MouseEvent.MOUSE_UP, stopDragging); function startDragging(event:MouseEvent):void { red_cat.startDrag(); } function stopDragging(event:MouseEvent):void { red_cat.stopDrag(); }
Links
Important manual pages
These are almost impossible to understand for non programmers, but otherwise the documentation at Adobe is excellent.
- InteractiveObject. This InteractiveObject class is the abstract base class for all display objects with which the user can interact, using the mouse and keyboard. Most Events are documented here. (Make sure to list also the inherited events).