In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

プリミティブな値の扱い

a = b = 1としたとき、
a = 1; b = 1;と同等の扱いなのか、
a = b; b= 1;と同等なのかを確かめる。

結果を見る限り前者でいいのかな。
Get Adobe Flash player
by madflash 01 Nov 2010
/**
 * Copyright madflash ( http://wonderfl.net/user/madflash )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6cqo
 */

// getter が呼ばれない…変数の参照なしにプリミティブな値の代入が行われてる?

package {
    import flash.display.Sprite;
    public class Substitution extends Sprite {
        private var trace:Tracer = new Tracer();
        private var _a:uint = 0;
        private var _b:uint = 0;       
        
        private function set a(a_:uint):void
        {
            trace.dev("call by set a: "+a_);
            _a = a_;
        }
        private function get a():uint
        {
            trace.dev("call by get a: "+_a);
            return _a;
        }
        private function set b(b_:uint):void
        {
            trace.dev("call by set b: "+b_);
            _b = b_;
        }
        private function get b():uint
        {
            trace.dev("call by get b: "+_b);
            return _b;
        }
        
        public function Substitution()
        {
            trace.property( { x:20, y:20 } );
            trace.isDevelop = true; 
            addChild( trace.create );
            
            //代入
            trace.push("代入のみ");
            a = b = 1;
            trace.push("参照(getterが呼ばれる)");
            a = b;
            
            trace.show();
        }
    }
}

import flash.system.IME;
import flash.display.*;
import flash.text.*;

class Tracer extends Sprite
{
    public var format:TextFormat;
    public var txt:TextField;
    private static const NEWLINE:String = "\n";
    private var _log:String = "";
    private var _isDev:Boolean = false;
    
    public function get create() :TextField { return txt }; //getter
    public function get log() :String { return _log };
    public function get isDevelop() :Boolean { return _isDev };
    public function set isDevelop(bool:Boolean) :void { _isDev = bool };
    
    public function Tracer(format_:TextFormat = null)
    {
        format = new TextFormat();
        txt = new TextField();
        //format
        var ref:* = (format_) ? format_ : {color:0x000000, size:12, font:'MS Gothic'};
        PropertyScan( format, ref );
        //prop
        var prop:Object = { x:0, y:0, autoSize:TextFieldAutoSize.LEFT };
        PropertyScan( txt, prop );
        //format done
        txt.defaultTextFormat = format;
    }
    // function has 4 params. implement dynamic param nomber.
    // x, y, width, height or Object/Array
    public function property(...args):void
    {
        const properties:Array = new Array('x','y','width','height');
        var isArray:Boolean = (args[0] is Array) ? true : false;
        var params:* = isArray ? args[0] : args;
        var Q:uint = params.length; //Queue
        
        if (isArray || (Q<=4 && !(params is Object)) ) for (var i:uint=0; i<Q; i++) txt[properties[i]] = params[i];
        else PropertyScan(txt, args[0]);
    }
    public function push(...args) :void { _log += Roller(args) + NEWLINE };
    public function show() :void { txt.htmlText = _log };
    public function dev(...args) :void
    {
        if (_isDev) _log += ("<b><font color='#ff0000'>" + Roller(args) + "</font></b>" + NEWLINE) ;
    }
    /* static functions, logic designed by madflash */
    private static function Roller(...args) :String
    {
        var str:String = "";
        if ( args.length <= 1 ) str += String(args);
        else for each(var e:Object in args){str += (String(e) + " ")};
        
        return str;
    }
    private static function PropertyScan(target:*, ref:*) :void
    {
        if (target is Object && ref is Object)
            for(var key:String in ref) target[key] = ref[key];   
    }
}