Hidden features/tricks of Flash development, Flash language (AS2/3), and Flash IDE?

Flash IDE This isn't a feature as much as it is a gotcha. When specifying a document class for an FLA, the compiler does not subclass that class, it modifies it. This can cause problems when you have several SWFs with the same document class, all being loaded into another SWF (since two classes with the same name cannot be loaded side-by-side into the same application domain).

It results in the first being loaded and the second using the first's modified class, producing weird errors (as you can imagine). The solution is either: Create a proxy class for each FLA that subclasses the document class Load each SWF into a new child application domain.

2 oh.. I see this is the correct answer! 8P – dome Feb 24 '10 at 10:51.

AS3 Tips for working with arrays or Vectors Fastest way through an array, always from the back var i:int = array. Length; var item:Object; while(i--) { item = arrayi; } Clearing an array, //faster than array = array. Length = 0; //garbage friendly while(array.

Length) { array.pop(); } Pushing and splicing //faster than array.push(); arrayarray. Length = "pushed value"; //faster than splice(index, 1) var index:int = array. IndexOf(splicee); arrayindex = null; array.

Splice(array. Length, 1); Cloning //fastest way to clone var newArray:Array = array.concat(); //fastest manipulation var mapFunction:Function = function(item:Object, index:int, source:Array):Object { return //your cloning or morphing here } var newArray:Array = array. Map(mapFunction).

MovieClip.addFrameScript() is a undocumented ActionScript 3.0 feature that allows you to specify a function that is called when the playhead of the Movieclip timeline enters a particular frame number. Function someFunction():void { } movieclip_mc. AddFrameScript(4,someFunction); The frame number is zero based (1st frame = 0) and needs to be whole numbers only, however if you wanted to use frame labels you could use something like this: function addFrameLabelScript(frame:String, func:Function):void{ var labels:Array = currentLabels; for(var i:int=0;iLength;i++){ if(labelsi.Name == frame){ addFrameScript(labelsi.

Frame-1,func); } } }.

Graphics::drawRoundRectComplex (x:Number, y:Number, width:Number, height:Number, topLeftRadius:Number, topRightRadius:Number, bottomLeftRadius:Number, bottomRightRadius:Number) : void; It's not documented anywhere, but a forum post explains more.

– Artem Russakovskii Jul 21 '09 at 21:13.

AS3 When you use the trace statement in AS3 you can pass in multiple parameters and AS3 will format the output so that there is a space between each. Trace(""World"); would output " AS2 does not support multiple parameters for trace so you are forced to do something like trace(" "+"World").

ActionScript 2 every class is a function and every function a class ... AS2 is prototype based ... trace. Prototype = { }; var f = trace; trace(new f());//will yield object Object accessing Function::prototype allows extending classes at runtime: MovieClip.prototype. Moo = function () { trace(this+" says 'moooooooo' ..."); } _root.moo();//_level0 says 'moooooooo' ... Object::__proto__ ... allows you to change the prototype of an object, which can be used for runtime reclassing: var o = trace; o.

__proto__ = ; trace(o. Push("foo", "bar", "foobar"));//3 here trace(o. Length);//also 3 trace(o1);//bar in this example, the function trace is reclassed to Array ... pretty cool, huh?

:) Function::apply and Function::call allow applying any function as a method to any object: Array.prototype.push. Apply(trace,1,2,3); trace(trace. Length);//3 trace(Array.prototype.splice.

Call(trace, 1,1));//2 ... actually, this is 2 (the array containing 2) using the three above, instantiation of a class MyClass with parameters param_1, ..., param_n can be written as: var instance = {}; instance. __proto__ = MyClass. Prototype; MyClass.

Call(instance, param_1, ..., param_n); a corelation of Function::push and Function::apply is that this is simply a function argument, that is passed automatically ... as any other function argument, it can be written to ... var f:Function = function () { this = ; this. Push(1,2,3); trace(this);//1,2,3 this = _root; trace(this);//_level0 } f(); Object::__resolve ... settings this method allows you to react to lookups on undefined properties ... this is fun and useful for proxying, mocking, composition, delegation, and so on ... import mx.utils. Delegate; var jack:Carpenter = ... var jim:BlackSmith = ... ... var guys:Array = jack, jim, ... var o = { __resolve : function (name:String) { for (var i:Number = 0; I Length; i++) { var guy = guysi; if (guy.

HasOwnProperty(name)) { var ret = guyname; if (ret instanceof Function) { ret = Delegate. Create(guy, return); } return return; } } return "sorry man, but nobody knows, what '" + name + "' means"; }); //some really imaginary stuff (i hope it makes the point): trace(o. Saw);//object Hammer trace(o.

Anvil);//object Anvil trace(o. Ventilator);//"sorry man, but nobody knows, what 'ventilator' means" trace(o.makeSword());//object Sword that's it for now ... there's an awfull lot more ... the thing is simply, that AS2 is an exiting language, but painfully slow ... AS3 in comparison is boring as hell, but the speed increase is really great ...

AS3 When looking for a the value of a variable, the player will run up the scope chain until it finds what it's looking for. So using nested (anonymous) functions you do things like make asynchronous calls and handle it using variables that were defined on the scope of the calling method. E.g.

Function loadData(myAwesomeObject : AwesomeObject) : void { var urlLoader : URLLoader = new URLLoader(); urlLoader. AddEventListener(Event. COMPLETE, function(event : Event) : void { myAwesomeObject.

SomeReallyAwesomeMethod(event. Target); }); urlLoader. Load(new URLRequest("http://someService")); } Loads of other uses for this and it's really very useful.

Anonymous functions will screw up debugging since they are not part of a helpful scope chain. Plus, they are really hard to read and make maintenance a chore. – Tim B.

Feb 24 '10 at 22:22 1 They most certainly do not screw up debugging. You can step through an anonymous function no problem. Plus the addition of an extra scope level when used properly is a helpful construct.So long as they are succinct in their contents they are not hard to read.

Granted a hundred line anonymous function is wrong. 5-10 lines of code is perfectly readable and mainatinable. – James Hay Feb 25 '10 at 11:27 1 @Tim B - I'm far from Adobe's biggest fan, but your misunderstanding of closures hardly equates to them "screwing up" debugging.

– Richard Szalay Feb 25 '10 at 11:33 1 @Tim B - The method stack always contains the method from which the anonymous method was called and can be navigated to in within the FB debugger. I don't doubt that you've seen misuse of closures, but any feature can be misused. – Richard Szalay Feb 25 '10 at 14:41 1 Fair enough, I have developed a deep mistrust of this kind of coding approach and avoid it.

– Tim B. Feb 25 '10 at 15:03.

For those of you using FlashDevelop, there is some nifty conditional compilation functionality: // Use it to generate different code paths CONFIG::debug { txt. Text = "Debug Version running..."; } CONFIG::release { txt. Text = "Welcome to Stark Industries"; } // Or use it as a const in code if ( CONFIG::debug && yourCondition ) { // Do stuff } read more about it here.

I would like to do something like if(CONIFG::debug) { nant debug } else { nant } – JPS Sep 13 at 9:07.

Its not really hidden (very obscured in the documentation), but updateAfterEvent is quite an unknown and useful method under certain circumstances...

AS3 The || (logical or) operator can be used for any truthy/falsey values. Var obj : Object = nullObject || instance; // instance var val : int = 5 || 10; // 5 var val : int = 0 || 10; // 10 Also, you can use & and | (bitwise and/or) to do a non-short-circuted expression: function functionA() { return false; } function functionB() { return true; } if (functionA() && functionB()) { trace("something"); } // methodB won't be executed if (functionA() & functionB()) { trace("something"); } // methodB WILL be executed.

AS3 I wouldn't necessarily call this a 'feature', but you can actually access variables before they are defined (even with strict compilation) due to the way the compiler works: trace(hb); // null var hb : HBox = new HBox; trace(hb); // object It can actually lead to frustration when refactoring code (since it compiles).

I read somewhere that this is because when a function runs, it will run through the entire function once first and declare every local variable. Only after that will it start execution of the function. – Max Dohme Mar 8 at 14:25 @EyeSeeEm - Very likely true for AS2, but in AS3 it's simply the way it's compiled.

– Richard Szalay Mar 8 at 20:45.

Flash IDE When you export a MovieClip as a swc you can add it to the components panel of by dropping it into the folder C:\Documents and Settings\USER_NAME\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Components\SOME_COMPONENT_FOLDER Restart flash and it'll be in the components panel for you to use.

1 Vista/7 don't call it "Documents and Settings". %userprofile%\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Components\SOME_COMPONENT_FOLDER will work for all versions. – Richard Szalay Jul 24 '09 at 8:30.

Well this might not be a hidden feature but maybe people have missed that there are external tweening engines you can use. My latest favourite is Greensocks. The only thing in my opinion it has lacked seems to be improving, workflow.

Have not tested v.11 yet but definitely will on my next AS project: blog.greensock.com/v11beta.

You can't touch tweenlite, I'm just a little concerned about the license. Tweensy is also very good/fast. – PiPeep Nov 16 '09 at 1:02.

You can create weak references in ActionScript3 by using the Dictionary object.

When using flashvars write a utility method getFlashVars(). Function getFlashVars():Object { return Object(LoaderInfo(this. LoaderInfo).

Parameters); } then when I'm coding I always add an extra || so that I won't have to flashvars while debugging. LocalVar = getFlashVars(). SampleVar || "default.xml.

I'm sure you will find usefull this article by jpauclair: AS3 hidden treasure in the mm. Cfg file.

Very useful for faking multiple inheritance (when used side by side with an interface), even if it usually is a bad practice.

As3 prototype based inheritance : import flash.display. MovieClip; var myRectangle = function(target,x,y){ var internalTarget = target; var myMovieClip = new MovieClip(); var myGraphic = myMovieClip. Graphics; myGraphic.

BeginFill(0xAAAAAA); myGraphic. DrawRect(0,0,100,100); myGraphic.endFill(); trace(typeof internalTarget); Sprite(internalTarget). AddChild(myMovieClip); myMovieClip.

X = x ; myMovieClip. Y = y ; } var aRectangle = new myRectangle(this,10,10).

Custom metadata isn't something that's well documented or promoted, but it's very helpful - without modifying a variable or changing its namespace, you can give it custom annotations similar to the way that you can in Java. It is gone over in depth by Christophe Conraets on his blog. The simplicity of it is that you can put all of your own metadata, and then you just use describeType() and you will see all of your custom metadata at run time :).

Here's another gotcha: By default Flash tools strips any metadata tags that you have. Many frameworks depends on these metadata tags. What you need to be careful is that this doesn't only apply to the compiler, but also to the optimizer.Be sure to run both your compiler and optimizer with -keep-as3-metadata-tag option to keep your metadata tag in there.

Here's something most people don't know: MouseEvents are tracked outside of the application window if the MOUSE_DOWN event has been fired, but not MOUSE_UP. You can grab mouse positions outside of the application window (and even outside of the browser window) as long as whatever you're doing makes the user hold their mouse down. To test this, try running the following code.

This package will get you all the DisplayObjects in DisplayObjectContainer by setting class types. Note: It won't count frames in MovieClips. Package { import flash.display.

DisplayObject; import flash.display. DisplayObjectContainer; import flash.utils. GetQualifiedClassName; /** * * @author Cansın Şenalioğly @ cansin.

Senalioglu@gmail. Com * */ //-------------------------------------- // Class description //-------------------------------------- /** * Gets all DisplayObject types in DisplayObjectContainer. * * @langversion 3.0 * @playerversion Flash 9.0.28.0 * @includeExample examples/ButtonExample.As * * @playerversion AIR 1.0 */ public class DisplayObjectFinder { /** * * * * Gets all DisplayObject type in DisplayObjectContainer * Example: * var items:Array = DisplayObjectFinder.

GetAllDOTypeInDOC(stage,MovieClip,callBack); * trace(items. Length); * function callBack(object:MovieClip):void{ trace(object.Name) }; * * @param container Objects parent (DisplayObjectCotainer); * @param typeClass Objects Class type; * @param forEach For every object call back function; * * @langversion 3.0 * @playerversion Flash 9.0.28.0 * * @playerversion AIR 1.0 */ public static function getAllDOTypeInDOC(container:DisplayObjectContainer,typeClass:Class,forEach:Function=null):Array { var a:Array = ; var len:int = container. NumChildren; while(len--){ var o:DisplayObject = container.

GetChildAt(len); if(flash.utils. GetQualifiedClassName(o) == flash.utils. GetQualifiedClassName(typeClass)){ aa.

Length = o; if(forEach! = null) forEach(o); } if(o is DisplayObjectContainer){ var aa:Array = getAllDOTypeInDOC(o as DisplayObjectContainer,typeClass,forEach); var lena:int = aa. Length; while(lena--){ aa.

Length = aalena; } } } return a; } } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions