Results 1 to 15 of 663
Thread: ActionScript 3 Tip of the Day
-
June 19th, 2006, 08:02 PM #1
ActionScript 3 Tip of the Day
ActionScript 3 is the next step forward in Flash scripting and to help with the transition (for those of you deciding to make it), I thought I'd make a new Tip of the Day thread for ActionScript 3.0 to help people prepare (after 100 tips, they will no longer be provided daily).
Note: Many of these tips were created prior to the release of Flash and pertain to AS-only projects. Others were for use with the Alpha version of Flash (released prior to the full release of Flash). Most of these are noted as being for "Flash 9". Though much has changed in Flash CS3, most of those tips should still apply to it as well.
To code AS3, you'll need one of the following:
- Flash Professional CS3
- Free Flex SDK (with AS3 compiler)
- Flex Builder 2
- http://try.flex.org/ (online Flex MXML - with AS3 - compiler)
ActionScript 3 Tips and Tricks:
Latest Additions
(All categories are ordered from oldest (top) to newest (bottom))
- Use IEventDispatcher to type EventDispatcher objects
- What removeMovieClip() becomes in ActionScript 3
- How stage, root, and MainTimeline Fit Together
- Thinking "Outside Looking In" and not "Inside Looking Out"
General
- Change the frame rate of your movie
- Abstract Classes
- Deep Object Copies with ByteArray
- Determine Instance Class or Superclass
- Multiple Arguments in trace()
- Loading Text and XML with URLLoader
- Get Sound Spectrum Information
- Garbage Collection: Reference Counting & Mark and Sweep
- Weak References
- MXMLC: SWF Metadata Tag
- TextField.appendText()
- Access to stage and root
- No More Color Class; Use ColorTransform
- Array.indexOf (Array.lastIndexOf())
- System.totalMemory
- Closing Net Connections
- AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
- Class member enumeration
- Key.isDown in AS3
- Scale and Alpha Ranges
- Available ActionScript packages
- Numeric Calculations: Number vs. int Speed
- Getting Around globally accessible _root and _global
- ActionScript 2 to ActionScript 3 Converter
- Accessing FlashVars and HTML Parameters
- ActionScript Speed Through Typing
- LivePreview and the LivePreviewParent class
- Flex Component Kit for Flash CS3
- Loading URL encoded Variables
- Interactive Masks
- No _lockroot
- Loading a Cross-domain Policy File
- Loading External Classes with ApplicationDomain
- Save Memory When Reusing Bitmaps With the Same BitmapData
- ActionScript SWFs and Version Compatibility
- Use IEventDispatcher to type EventDispatcher objects
- How stage, root, and MainTimeline Fit Together
- Thinking "Outside Looking In" and not "Inside Looking Out"
Language Elements/Behavior and Syntax
- Class scope is now bound to class methods
- New Variable Types
- New Import Directive
- Type Casting and the as Operator
- Unique Class Variables
- The delete Keyword and Class Members
- Label Statements
- Commas in Shorthand Array Definitions
- Package Block
- Same-file Helper Classes
- Access Attributes
- The override Keyword
- Using prototype
- Similarly Named Instance and Static Properties
- super() Placement (Now Anywhere)
- is Operator (vs instanceof)
- Number() Conversion No Longer Interprets Octals
- Changes in typeof
- for..in and for each..in
- Default Values for Function Parameters
- Undetermined Number of Arguments With ...(rest)
- arguments
- Support for Namespaces
- Namespaces: Name Qualifier Operator (::)
- dynamic is Not Inherited
- Prevent Overriding and Subclassing with final
- in Operator
- Constants
- include Directive
- Duplicate Variable Definitions
- Namespaces: use namespace Directive
- asfunction: Now event:
- No more random(); Use Math.random()
- Property Access and Downcasting (parent, root, etc.)
New Classes
- The Dictionary Class
- SimpleButton Instances
- Regular Expression (RegExp) Support
- EventDispatcher
- URLRequest for URL Strings
- XML vs. XMLDocument
- Timer Class
- ByteArray Class
- Animator class in AS3 (Flash CS3)
- Loading External SWFs with Loader (Preloading)
- Loading External Classes with ApplicationDomain
Regular Expressions
Proxy Class
- Proxy Class
- Proxy: getProperty and setProperty
- Proxy: callProperty
- Proxy: Property Enumeration (nextName(), nextValue(), and nextNameIndex())
XML
- Writing Inline XML
- XML vs. XMLDocument
- XML: @ Operator for Attributes
- XML: XML and XMLList
- XML: Children (.) and Decendants (..)
- XML: Removing Nodes
Events
- New MouseMove Behavior
- Detecting When the Mouse Leaves the Movie
- EventDispatcher
- Events and Event Types
- Calling Event Handlers without Events
- Render Event
- Event Propagation Support
- rollOver and rollOut vs. mouseOver and mouseOut
- Creating a mouseWithin Event
- mouseEnabled and Event Blocking
- mouseChildren with Event Propagation
- Cleaning Up Event Listeners
- Event Phases and Event Capturing
- Determining Event Phase
- Preventing Event Propagation
- Global Events
- Detecting a mouseUp Outside
- Event Capturing and mouseEnabled
- Overriding clone in Events
- Use IEventDispatcher to type EventDispatcher objects
Errors and Error Handling
- Runtime Errors; Error Class
- Errors: try..catch..finally and Exception Handling
- Errors: Asynchronous Exception Handling
- Errors: Referencing properties from a null reference
Display Objects (MovieClips)
- Graphics Object and the Drawing API
- Display Objects
- SimpleButton Instances
- Approach to Depth Sorting
- Determining Current Frame Label
- getBounds() vs getRect()
- duplicateMovieClip Replacement
- Creating graphics Copies
- DisplayObjectContainer contains()
- Detecting Addition to or Removal from Stage
- Adding an isPlaying Property to MovieClips
- getObjectsUnderPoint
- Loading External SWFs with Loader (Preloading)
- Flash CS3: Frame Navigation and Child Access
- Save Memory When Reusing Bitmaps With the Same BitmapData
- What removeMovieClip() becomes in ActionScript 3
Flash Authoring
- Flash 9: Timelines as Classes
- Flash 9: BitmapData and Bitmaps from the Library
- Flash 9: Display Object Variables and Instance Names
- Flash 9: Document Class
- Flash 9: Strict Mode
- Flash 9: Timeline navigation and code execution
- Flash 9: addFrameScript
- Flash CS3: Setting MovieClip Base Classes
- Flash CS3: Changing Function Behavior Across Frames
- Flash CS3: New Library BitmapData Instances
- Flash CS3: Frame Navigation and Child Access
- Flash CS3: Automatic Timeline Declarations
- Flash CS3: Component Classes
Additional Resources:
- Beginners Guide to Getting Started with AS3 (Without Learning Flex) - uses SDK for MXMLC
- Getting Started with ActionScript 3.0 in Adobe Flash CS3
- ActionScript 3 Language Reference
- ActionScript 2 to ActionScript 3 Migration Guide
- Adobe ActionScript Technology Center
- ActionScript 3 Overview
- ActionScript 3 Learning Tips
- ActionScript Cheetsheets and References
- Programming ActionScript 3 (PDF)
- Flash Player 9 Security (PDF)
- ActionScript 3 and AVM 2.0 Performance Tuning (PDF)
Samples:
-
June 19th, 2006, 08:03 PM #2
Change the frame rate of your movie
Using ActionScript 3, you can dynamically change the frame rate of your movie using the Stage class.
The Stage class (flash.display.Stage) is the class assigned to the stage object which is accessible from your main movie sprite/movie clip (or others within the same security sandbox) using the stage property. The stage object has a frameRate property which can contain any value between 0.01 and 1000 and determines the frame rate at which the Flash player plays back your movie. Changing this value lets you change the frame rate at runtime.
Code:// change frame rate to 12 fps: stage.frameRate = 12;
-
June 19th, 2006, 09:08 PM #3
Nice to have an AS 3 thread. Maybe whole Flex/AS3 forum would be usefull as it seem to spred a lot.
To the stage thing... is "stage" and not "Stage" a typo or do you need to import and instance the Stage to change the framerate? Shouldnt flash.display.Stage.frameRate = 12 do the job then?
-
June 19th, 2006, 09:18 PM #410,202Registered User
postsChanging FPS with AS? Isnt this a dream come true?
-
June 19th, 2006, 09:26 PM #5No, in AS3 it has changed - the Stage class is accessed through the stage property of a DisplayObject instance. However, they all reference the same thing I think.
Originally Posted by mathew.er
Proud Montanadian
We tolerate living and breathing. And niches.
Name Brand Watches
Maybe getTimer() or TweenMax is the answer to your problem . . .
-
June 20th, 2006, 01:33 AM #6Thats how I understand it.However, they all reference the same thing I think.
http://livedocs.macromedia.com/labs/...lay/Stage.htmlInheritance:Stage->DisplayObjectContainer-> InteractiveObject->DisplayObject ->EventDispatcher->Object
The Stage class represents the main drawing area. The Stage represents the entire area where Flash content is shown.
The Stage object is not globally accessible. You need to access it through the stage property of a DisplayObject instance.
-
June 20th, 2006, 02:27 AM #7
So that example at livedocs makes it pretty clear... "stage" is a global object allowing you to view and change its properties or to register events with it.
@fabiopb: Why? Isnt this just a sign, that flash goes on pretty well? If your worried anout the Adobe Flash application itself, then you dont need to be... Flex is just for something else than Flash. It wont also disappear from the Internet as everybody has the plugin, people are used to use it and it still has great potential.Code:package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; public class StageExample extends Sprite { public function StageExample() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; stage.addEventListener(Event.ACTIVATE, activateHandler); stage.addEventListener(Event.RESIZE, resizeHandler); } private function activateHandler(event:Event):void { trace("activateHandler: " + event); } private function resizeHandler(event:Event):void { trace("resizeHandler: " + event); trace("stageWidth: " + stage.stageWidth + " stageHeight: " + stage.stageHeight); } } }
-
June 20th, 2006, 02:34 AM #881Registered User
postsone more step towards making AS to Java!! Great!!
-
June 20th, 2006, 09:55 AM #9
-
June 20th, 2006, 10:12 AM #10
Class scope is now bound to class methods
ActionScript 3 is entirely class-based. When you create classes, you create variables and functions (methods) which relate to and work with that class and instances of that class. Unlike ActionScript 2, methods in ActionScript 3 now retain their class scope when called, even if assigned to another object and called from that object, or if used with Function.call and Function.apply. Example:
Code:package { import flash.display.Sprite; public class ClassScope extends Sprite { public function ClassScope() { traceThis(); // "Class Instance" var obj:Object = new Object(); obj.traceThis = traceThis; obj.traceThis(); // "Class Instance" traceThis.call(new Sprite()); // "Class Instance" } public override function toString():String { return "Class Instance"; } public function traceThis():void { trace(this); } } }
-
June 20th, 2006, 12:09 PM #11
this topic at least should be a sticky !
thx Senocular.
-
June 20th, 2006, 12:28 PM #12
-
June 20th, 2006, 12:42 PM #13
Nice one, sen
"60% of the time it works... every time." -- Paul Rudd as Brian Fantana.
-
June 20th, 2006, 01:51 PM #1410,202Registered User
postsA few questions...Whats AS 3.0 for? Is there a new flash coming out?
And PK...why do you believe flash will decline?
-
June 20th, 2006, 01:59 PM #15ActionScript 3 is the next release of ActionScript that will be supported in Flash Player 9. Flex 2 applications are built using ActionScript 3 and the next version of Flash (code named BLAZE) will support it when it's released some time after Flex. Unlike ActionScript 2, ActionScript 3 uses an entirely new virtual machine providing it with new robust features and increased performance.
Originally Posted by ~REEF~
More details on available and upcoming products can be found on http://www.adobe.com/ and http://labs.adobe.com/ (where both the Flex 2 beta and Flash Player 9 beta are currently available for download)



Reply With Quote


Bookmarks