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

Thread (そうめん) お勉強その1

〜外部画像を読み込んで配置するだけの、かんたんなお仕事〜
Get Adobe Flash player
by ProjectNya 27 Oct 2010
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hMnY
 */

////////////////////////////////////////////////////////////////////////////////
// Thread (そうめん) お勉強その1
//
// 〜外部画像を読み込んで配置するだけの、かんたんなお仕事〜
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.system.Security;
    import org.libspark.thread.Thread;
    import org.libspark.thread.EnterFrameThreadExecutor;

    [SWF(backgroundColor="#333333", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var filePath:String = "http://www.project-nya.jp/images/flash/piyo.png";
        private var thread:MainThread;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            graphics.beginFill(0x333333);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            //
            if (!Thread.isReady) Thread.initialize(new EnterFrameThreadExecutor());
            start();
        }
        private function start():void {
            Security.allowDomain("www.project-nya.jp");
            Security.loadPolicyFile("http://www.project-nya.jp/crossdomain.xml");
            thread = new MainThread(this, filePath);
            thread.start();
        }
        
    }

}


//////////////////////////////////////////////////
// MainThreadクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.Loader;
import flash.display.Bitmap;
import flash.net.URLRequest;
import org.libspark.thread.Thread;
import org.libspark.thread.threads.display.LoaderThread;

class MainThread extends Thread {
    private var container:Sprite;
    private var filePath:String;
    private var loader:LoaderThread;

    public function MainThread(c:Sprite, f:String) {
        container = c;
        filePath = f;
    }

    override protected function run():void {
        loader = new LoaderThread(new URLRequest(filePath));
        loader.start();
        loader.join();
        next(loaded);
    }
    private function loaded():void {
        var loader:Loader = loader.loader;
        var content:Bitmap = Bitmap(loader.content);
        container.addChild(content);
        content.x = 32;
        content.y = 32;
    }
    override protected function finalize():void {
    }

}