![]() |
Writing Inline XML
In ActionScript 3, you can define XML variables using inline XML in your script. You don't even need to enclose it in Strings like you did in previous versions of ActionScript. The ActionScript 3 compiler will automatically parse the XML in the code and recognize when it stops and when normal AS code starts.
ActionScript Code:
|
Hey senocular, jus wondering if you can post something about the new URLLoader and URLRequest use with PHP. Thanks in advance.
|
Quote:
|
Determine Instance Class or Superclass
ActionScript 3 lets you easily obtain any instances class name using a new function called getQualifiedClassName (flash.utils.getQualifiedClassName).
ActionScript Code:
You can also use the getQualifiedSuperclassName (flash.utils.getQualifiedSuperclassName) function to find its superclass ActionScript Code:
If you want to go backwards, and convert a string into an actual class reference, you can use getDefinitionByName (flash.utils.getDefinitionByName). ActionScript Code:
Also see describeType() (flash.utils.describeType) in the following post... |
that's beautiful.. so much better than typeof.. Though I might also add (if I may), if you want some extremely (almost stupid amount of) detailed info about your class type, you can also use describeType()..
so ActionScript Code:
traces: Code:
<type name="flash.display::Sprite" base="flash.display::DisplayObjectContainer" isDynamic="false" isFinal="false" isStatic="false">I just love AS3... really, I do... |
I was going to save that as a tip for another day :bad: but thanks :trout:
|
Sen, question about getDefinitionByName(). Does the class need to be hardcoded into the file before using the returned value for getDefinitionByName()? Example:
I have a pageType field in a MySQL database that tells the Flash site which page template to use for its pages. Homepage, Aboutpage, etc. I use: ActionScript Code:
To create each page. The problem is, I need to hardcode an instance of each of these page classes into my site so that file will load and keep the class. ActionScript Code:
I'd like to skip that step, seeing as how I could have it completely dynamic if I didn't have to hardcode in anything. |
You should need to at least import the needed classes into your file if not native player classes. If you dont, Flash will not have them in the SWF to use. With AS3, instantiation shouldnt be required (and really, with AS2, it wasnt either as long as you used the class reference somewhere).
|
Quote:
whoops.. sorry - seemed to fit the topic... |
I almost added it as part of that one, but I was starting to get a little thin on topics, and since they were every day I'm going to try to stretch them out. Not a big deal ;)
|
super() Placement (Now Anywhere)
In ActionScript 2, the call to super() in the constructor of a class inheriting from another class had to be the first statement within the constructor. If you didn't add it explicitly yourself, it was added for you.
In ActionScript 3, super will still be added for you if you did not include it yourself, but now you are allowed to place it anywhere within your constructor, even after other statements; it no longer has to be the first statement in your constructor. ActionScript Code:
|
super() Placement (Now Anywhere)
In ActionScript 2, the call to super() in the constructor of a class inheriting from another class had to be the first statement within the constructor. If you didn't add it explicitly yourself, it was added for you.
In ActionScript 3, super will still be added for you if you did not include it yourself, but now you are allowed to place it anywhere within your constructor, even after other statements; it no longer has to be the first statement in your constructor. ActionScript Code:
|
Just a little FYI - I changed the links in the index to reference the posts in the context of the thread. This makes it a little easier to go through and read related posts as well :)
|
If you extend a class, the constructor for the extended class won't run upon instantiation, but it can still be accessed with super, correct?
|
the super class constructor will still run, you can just decide when now (AS2 it was always before any other code).
|
You might want to edit the override post to mention that when you override methods that use the AS3 namespace, you need to include the namespace in your override definition.
The post mentions the need to match the method signature, but it probably took me half of an hour to figure out that I needed to include the namespace to avoid an error I was getting when overriding Array.push(). |
Determining Current Frame Label
MovieClip (flash.display.MovieClip) instances in ActionScript 3 have a couple of new properties called currentLabels and currentLabel. currentLabels is an array of FrameLabel (flash.display.FrameLabel) instances describing the frame labels within the movie clip's timeline. Each FrameLabel in the currentLabels array contains two properties: name, and frame. Name provides the name of the label and frame is the frame number on which it exists. currentLabel returns the name of the label associated with the current frame.
ActionScript Code:
|
Multiple Arguments in trace()
As with previous versions of ActionScript, there exists a trace function for outputing messages into the Output panel in Flash. In ActionScript 1 and 2, trace accepted one argument that was outputed to the Output panel in Flash. In ActionScript 3, trace now accepts any number of arguments and outputs them each.
ActionScript Code:
Note: You could get essentially the same effect in AS1 and AS2 using ActionScript Code:
using an array ;) |
Calling Event Handlers without Events
When you define event handlers in ActionScript 3, the functions need to accept 1 parameter of the type Event. When these methods are called by the events, those event objects are then passed into the handler.
If you have an event handler that you want to use as a normal function call, you can call that function with a new Event object passed into it like so: ActionScript Code:
However, that can be a hassle and a little confusing (plus you are creating an event that probably has nothing to do with the function). If you just want to be able to call the event handler without having to worry about that event but still have it work for calls coming from events, you can define the handler with your event parameter having a default value of null. This way you can call the function without an event but still have it work when the event is passed from an actual event call. ActionScript Code:
Note: this will not work if your event handler relies on information from the event object. |
URLRequest for URL Strings
Methods relying on URL strings in ActionScript 3 now use URLRequest (flash.net.URLRequest) instances instead of direct string values for URLs. URLRequest instances contain the following properties:
For example, when using navigateToURL() (flash.net.navigateToURL) (getURL() replacement), instead of passing a string of the URL to navigate to, you use a URLRequest instance. ActionScript Code:
|
eval() is removed...
|
XML vs. XMLDocument
XML has changed for ActionScript 3. The new way of dealing with XML revolves around E4X - ECMAScript's XML specification. This provides a different, more efficient interface for dealing with XML nodes and attributes. These are all associated with the new XML (top level XML) class.
ActionScript Code:
ActionScript Code:
The old class, as it was used in ActionScript 1 and 2, is still around. However, it has been renamed to XMLDocument (flash.xml.XMLDocument). If you want to work with XML the way you did with AS1 and AS2, you would use XMLDocument instead of XML. ActionScript Code:
|
Loading Text and XML with URLLoader
In previous versions of ActionScript, there were a couple of classes who had the capability of loading external text, namely LoadVars and XML. The loading responsibilities of these classes has moved to one single class in ActionScript 3, URLLoader (flash.net.URLLoader). This class is a lot like LoadVars. The big difference is that it is used for XML since the responsibility of loading XML from an external source has been removed from the XML class. Instead, you would load the text with URLLoader and then give that text to an XML object for parsing.
Like LoadVars, URLLoader has a load() method that is used to load text from an external source. This accepts 1 argument, a URLRequest instance (NOT a URL string). You can then use events from URLLoader to determine when the loading is complete. When complete, the text loaded is available in the data property of URLLoader. Example: ActionScript Code:
|
Where can i download the Flash 9 Player application from? I don't want the plugin.
|
Quote:
|
Quote:
is there anyway so i can make a function (or class method) that accepts any number of arguments? |
|
wow, thats cool!
now, one more question... is there anyway to pass that array as single arguments for another function? something like: ActionScript Code:
|
use Function.apply() just like in AS1 and AS2
|
ohh, i never used that :P
thanks ;) |
is Operator (vs instanceof)
The is operator (is operator) is a new keyword that lets you check to see if an instance is of a certain object type. This works for ActionScript 3 class instances checked against class types as well as interfaces. Ex:
ActionScript Code:
The is operator is a replacement for instanceof (instanceof operator) from ActionScript 1 and 2. The is operator, however, is specific to AS3 classes and is used to check the inheritance specific to those classes. This will not work on dynamic classes created with AS1-style constructor functions. In that situation, you would use instanceof since instanceof checks the prototype chain of an instance as opposed to class inheritance (which is does). Because an AS3 class's class inheritance is mirrored in its prototype chain, this means that instanceof will also work for AS3 classes, though is is prefered then (and less typing!). ActionScript Code:
ActionScript Code:
|
Flash 9: Timelines as Classes
In Flash 9, you are able to associate all timelines with classes, including the root timeline. Movie clip timelines are associated with classes the same way as ActionScript 2 using the linkage dialog. The root timeline can be given a class association through the property inspector or through the publish settings (in ActionScript settings).
If you do not associate a timeline with a class, one is automatically created for that timeline by Flash. When this happens, variables become class variables, all named functions (declared using function functionName(){}) become methods of that class, and all scripts within the frames associated with methods that are automatically called when that frame is reached (minus the variable and method definitions). Because of this, you can only declare variables and named functions of any specific name for a function once. Variables you can redefine, but not redeclare. Functions (methods) are locked. Note: You cannot mix classes associated with timelines and timeline scripts. The following timeline script in Flash 9 ActionScript Code:
essentially becomes the following AS3 class that gets associated with that timeline: ActionScript Code:
|
RegExp: Email Validation
Here's an example of how one might validate email using ActionScript 3's Regular Expression class (Top level RegExp):
ActionScript Code:
|
Render Event
ActionScript has long since relied on the enterFrame (onEnterFrame) event for time-based actions, especially animation and actions relating to frame playback. In comparison, Director's Lingo language has, not only an enterFrame event, but two other frame events, prepareFrame and exitFrame. Though ActionScript 3 has not aquired prepareFrame or exitFrame, it has gained a new frame event, render, or Event.RENDER (flash.events.Event.RENDER).
The render event in AS3 is a frame event that occurs after enterFrame (flash.events.Event.ENTER_FRAME) allowing one more chance to do what you need to do before the screen updates its display. Unlike enterFrame, however, the render event will not be called unless the display object using it is attached to a stage (or in any display list attached to the stage). Also, render is not automatically called every frame, even if attached to the stage. In order for render to be called for the current frame, you must make a call to stage.invalidate() (flash.display.Stage.invalidate()); Ex: ActionScript Code:
Code:
Output: |
XML: @ Operator for Attributes
E4X (XML used in ActionScript 3) has new operators to access values in XML. One operator is the @ operator which accesses attributes. It can be used in place of the attribute() (Top level XML.attribute()) method for obtaining attribute values. Ex:
ActionScript Code:
You can also use an asterisk (*) with the @ operator to get a list of all attributes associated with an XML node in the form of an XMLList object. This is equivalent to the attributes() (Top level XML.attributes()) method. Ex: ActionScript Code:
|
sorry about the delay this week; I got slammed at work :)
|
Quote:
With getDefinitionByName you should in theory be able to do some basic Object Reflection ? I guess you would have to do the method information manually though... |
Quote:
|
Event Propagation Support
ActionScript 3 now supports event propagation - the transference of a single event applying to multiple objects to each of those objects instead of one - in Display objects. In ActionScript 1 and 2, "Button" events (such as onPress, onRelease, etc.) handled by movie clips were not propagated to that movie clip's children. This means that though visually you were clicking on a child of a movie clip handling an onPress event, that onPress would never make it to the child because the parent movie clip handling the event would intercept it and prevent the propagation of the onPress event to that child.
Example; movie clip parent_mc contains child_mc: ActionScript Code:
ActionScript Code:
In ActionScript 1 and 2, the child is never able to receive the event. In ActionScript 3, both movie clips are able to receieve it as the event is propagated to each movie clip to which it applies. |
Get Sound Spectrum Information
Using ActionScript 3 you can now obtain sound spectrum information from audio played through Flash. This lets you create visualizations like those seen in popular in media player applications. The class that provides this information is the SoundMixer class (flash.media.SoundMixer). It's computeSpectrum method (static) places sound spectrum information in a ByteArray instance which can then be used to generate a visualization.
ActionScript Code:
|
| All times are GMT -7. The time now is 02:02 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Copyright 2004 - kirupa.com