JAVAC.JP
HOSHI TETSUYA ―“S–ξ
2005/07/25
hossy@javac.jp
http://www.javac.jp
Google
WWW ‚πŒŸυ WWW.JAVAC.JP ‚πŒŸυ

A-2 ‰Ϋ‘θ2 - ‰π“š

‰Ϋ‘θ(2-1)
main.as
---
this.attachMovie("oval","oval",1);
stop();
‰Ϋ‘θ(2-2)
main.as
---
var test:TestClass=new TestClass(this);
stop();

ExXML.as
---
class ExXML extends XML{
    var ignoreWhite=true;
    var addEventListener:Function;
    var removeEventListener:Function;
    private var dispatchEvent:Function;
}

JpegClass.as
---
import mx.events.EventDispatcher;

class JpegClass extends MovieClip{
    private var id:String;
    private var x:Number;
    private var y:Number;
    private var url:String;
    private var seed:MovieClip;
    private var mcLoader:MovieClipLoader;
    private var imageListener:Object;

    function JpegClass(){
        mcLoader=new MovieClipLoader();
        imageListener=new Object();
        EventDispatcher.initialize(imageListener);
        imageListener.onLoadInit=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="onLoadImage";
            this.dispatchEvent(lo);
        }
        imageListener.addEventListener("onLoadImage",this);
        mcLoader.addListener(imageListener);
    }

    public function setId(id:String):Void{
        this.id=id;
    }

    public function setX(x:Number):Void{
        this.x=x;
    }

    public function setY(y:Number):Void{
        this.y=y;
    }

    public function setUrl(url:String):Void{
        this.url=url;
    }

    public function loadImage():Void{
        this.createEmptyMovieClip("seed",1);
        seed=this.seed;
        mcLoader.loadClip(url,seed);
    }

    private function onLoadImage():Void{
        var xsize:Number=100;
        var ysize:Number=100;
        seed._width=xsize;
        seed._height=ysize;
        seed._x=x*xsize;
        seed._y=y*ysize;
    }
}

TestClass.as
---
import mx.events.EventDispatcher;

class TestClass{
    var path:MovieClip;
    var imgList:Array;

    function TestClass(path:MovieClip){
        this.path=path;
        imgList=new Array();
        var x:ExXML=new ExXML();
        EventDispatcher.initialize(x);
        x.onLoad=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="onXMLLoad";
            lo.datas=x;
            this.dispatchEvent(lo);
        }
        x.addEventListener("onXMLLoad",this);
        x.load("xml/imgfiles.xml");
    }

    function onXMLLoad(eventObj:Object):Void{
        var datas:XML=XML(eventObj.datas);
        var xmlList:XMLNode=datas.firstChild;
        var xmlListNodes:Array=xmlList.childNodes;
        for(var key:String in xmlListNodes){
            var n:XMLNode=XMLNode(xmlListNodes[key]);
            if(n.nodeName=="img"){
                var o:Object=n.attributes;
                imgList.push(o);
            }else{
                trace("invalid node.");
            }
        }
        loadImgs();
    }

    function loadImgs():Void{
        var imgsDepth:Number=0;
        for(var i:Number=0;i<imgList.length;i++){
            var id:String=String(imgList[i].id);
            var x:Number=Number(imgList[i].x);
            var y:Number=Number(imgList[i].y);
            var url:String=String(imgList[i].url);
            var depth:Number=imgsDepth;
            imgsDepth++;
            var linkage:String="jpegHolder";
            var mcname:String="seed"+depth;
            path.attachMovie(linkage,mcname,depth);
            var mc:MovieClip=path[mcname];
            mc.setId(id);
            mc.setX(x);
            mc.setY(y);
            mc.setUrl(url);
            mc.loadImage();
        }
    }
}



BACKTOPNEXT




All Contents Copyright (C) 2005 HOSHI Tetsuya
Home