Hidden features/tricks of Flash development, Flash

2019-01-21 02:42发布

Guys, I am thoroughly surprised that there is no Flash Hidden Features post yet in the Hidden Features series that I've been tracking for a while now.

There is a recent AS3/Flex one but it's not very active and I don't exactly mean just AS3 when I say Flash here.

The Hidden Features series is great for people who are new to a certain language. It shows the ropes and certain valuable tricks, all in one place. I think it's a brilliant idea. Even experts sometimes find tricks they'd never heard about.

When I started with Flash, I was taken aback by the Flash IDE and odd concepts of Flash, compared to other programming languages.

So, here goes: what are some hidden features of Flash as a language (AS2/3) and the Flash IDE?

Let the fun begin.

24条回答
何必那么认真
2楼-- · 2019-01-21 03:32

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

查看更多
Animai°情兽
3楼-- · 2019-01-21 03:32

In Flash Professional, you can change a MovieClip symbol to a Sprite by redirecting it's base class from flash.display.MovieClip to flash.display.Sprite, and the symbol icon color in the library will change from blue to green.

enter image description here

enter image description here

查看更多
男人必须洒脱
4楼-- · 2019-01-21 03:33

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

查看更多
闹够了就滚
5楼-- · 2019-01-21 03:34

[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
查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-21 03:35

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: http://blog.greensock.com/v11beta/

查看更多
趁早两清
7楼-- · 2019-01-21 03:36

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(o[1]);//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 < guys.length; i++) {
        var guy = guys[i];
        if (guy.hasOwnProperty(name)) {
            var ret = guy[name];
            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 ...

greetz

back2dos

查看更多
登录 后发表回答