07-26-2006, 02:21 AM
|
#106
|

 |
Earth, SouthAmerica, Chile, Quinta Region, Viña del Mar, 4 norte 1329, third floor, my house, my room, in front of my computer. |
|
 |
666 |
|
|
Quote:
|
Originally Posted by Senocular
trace(value1, value2, value3);
|
is there anyway so i can make a function (or class method) that accepts any number of arguments?
__________________
My real name is: Cristián Arenas Ulloa.
Member #1 Of The NiñoScript's Club
Member #4 Of The I Want A Mac Club
Member #7 Of The Kirupa Anime Club
Member #1 Of The Courier Font Club
|
|
|
07-26-2006, 05:14 AM
|
#107
|
|
|
Quote:
|
Originally Posted by NiñoScript
is there anyway so i can make a function (or class method) that accepts any number of arguments?
|
Yep, use ... (rest). Senocular mentioned it in this post, and the documentation on it is here.
|
|
|
07-26-2006, 11:44 AM
|
#108
|

 |
Earth, SouthAmerica, Chile, Quinta Region, Viña del Mar, 4 norte 1329, third floor, my house, my room, in front of my computer. |
|
 |
666 |
|
|
wow, thats cool!
now, one more question... is there anyway to pass that array as single arguments for another function?
something like:
ActionScript Code:
function _trace(... rest):Array { trace(rest); /* well... this is not a good example couse trace can accept an array as argument... but think about a function that can accept any number of Numbers but does nothing if you pass an Array to it */ return rest; }
__________________
My real name is: Cristián Arenas Ulloa.
Member #1 Of The NiñoScript's Club
Member #4 Of The I Want A Mac Club
Member #7 Of The Kirupa Anime Club
Member #1 Of The Courier Font Club
|
|
|
07-26-2006, 01:57 PM
|
#110
|

 |
Earth, SouthAmerica, Chile, Quinta Region, Viña del Mar, 4 norte 1329, third floor, my house, my room, in front of my computer. |
|
 |
666 |
|
|
ohh, i never used that 
thanks 
__________________
My real name is: Cristián Arenas Ulloa.
Member #1 Of The NiñoScript's Club
Member #4 Of The I Want A Mac Club
Member #7 Of The Kirupa Anime Club
Member #1 Of The Courier Font Club
|
|
|
07-29-2006, 11:51 AM
|
#111
|
|
If you can read this, I'm
|

 |
San Francisco, CA (USA) |
|
 |
17,266 |
|
|
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:
var mySprite:Sprite = new Sprite(); trace(mySprite is Sprite); // true trace(mySprite is DisplayObject); // true trace(mySprite is IEventDispatcher); // true
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:
var mySprite:Sprite = new Sprite(); trace(mySprite instanceof Sprite); // true trace(mySprite instanceof DisplayObject); // true trace(mySprite instanceof IEventDispatcher); // false - not in prototype chain
ActionScript Code:
var AS1StyleClass:Function = function(){} AS1StyleClass.prototype = new MovieClip();
var as1Instance:* = new AS1StyleClass(); trace(as1Instance instanceof AS1StyleClass); // true trace(as1Instance instanceof MovieClip); // true trace(as1Instance is AS1StyleClass); // true trace(as1Instance is MovieClip); // false - cant see prototype chain
__________________

|
|
|
07-29-2006, 12:24 PM
|
#112
|
|
If you can read this, I'm
|

 |
San Francisco, CA (USA) |
|
 |
17,266 |
|
|
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:
var num:Number = 1; function showNum():void { trace(num); } showNum();
essentially becomes the following AS3 class that gets associated with that timeline:
ActionScript Code:
package { class TimelineClass extends MovieClip { public var num:Number;
public function showNum():void { trace(this.num); } public function frame1():void { num = 1; showNum(); } } }
__________________

|
|
|
07-29-2006, 01:16 PM
|
#114
|
|
If you can read this, I'm
|

 |
San Francisco, CA (USA) |
|
 |
17,266 |
|
|
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:
var sprite:Sprite = new Sprite(); stage.addChild(sprite);
sprite.addEventListener(Event.ENTER_FRAME, enterFrame); sprite.addEventListener(Event.RENDER, render); stage.addEventListener(MouseEvent.CLICK, click);
function enterFrame(event:Event):void { trace("enter frame"); } function render(event:Event):void { trace("render"); } function click(event:MouseEvent):void { trace("click"); stage.invalidate(); }
Code:
Output:
enter frame
enter frame
enter frame
click
enter frame
render
enter frame
enter frame
enter frame
enter frame
...
__________________

|
|
|
07-29-2006, 01:37 PM
|
#115
|
|
If you can read this, I'm
|

 |
San Francisco, CA (USA) |
|
 |
17,266 |
|
|
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:
var myXML:XML = <user name="senocular" id="2867" />; trace(myXML.attribute("name")); // senocular trace(myXML.attribute("id")); // 2867 trace(myXML.@name); // senocular trace(myXML.@id); // 2867
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:
var myXML:XML = <user name="senocular" id="2867" />; var atts:XMLList;
atts = myXML.attributes(); trace(atts.toXMLString()); /* Output: senocular 2867 */ atts = myXML.@*; trace(atts.toXMLString()); /* Output: senocular 2867 */
__________________

|
|
|
07-30-2006, 10:27 AM
|
#117
|
|
|
Quote:
|
Originally Posted by senocular
ActionScript 3 lets you easily obtain any instances class name using a new function called getQualifiedClassName ( flash.utils.getQualifiedClassName).
ActionScript Code:
var sprite:Sprite = new Sprite();
trace(getQualifiedClassName(sprite)); // "flash.display::Sprite"
You can also use the getQualifiedSuperclassName ( flash.utils.getQualifiedSuperclassName) function to find its superclass
ActionScript Code:
trace(getQualifiedSuperclassName (sprite )); // "flash.display: isplayObjectContainer"
If you want to go backwards, and convert a string into an actual class reference, you can use getDefinitionByName ( flash.utils.getDefinitionByName).
ActionScript Code:
trace(getDefinitionByName("flash.display::Sprite")); // [class Sprite]
|
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...
|
|
|
07-30-2006, 02:13 PM
|
#119
|
|
If you can read this, I'm
|

 |
San Francisco, CA (USA) |
|
 |
17,266 |
|
|
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:
// AS1 and AS2 parent_mc.onPress = function(){ trace("parent pressed"); } parent_mc.child_mc.onPress = function(){ trace("child pressed"); }
/* click child output: parent pressed */
ActionScript Code:
// AS3 parent_mc.addEventListener(MouseEvent.CLICK, parentClick); parent_mc.child_mc.addEventListener(MouseEvent.CLICK, childClick);
function parentClick(event:MouseEvent):void { trace("parent pressed"); } function childClick(event:MouseEvent):void { trace("child pressed"); }
/* click child output: child pressed parent pressed */
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.
__________________

|
|
|
|
Currently Active Users Viewing This Thread: 27 (0 members and 27 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 11:21 AM.
|
|