import mx.events.EventDispatcher import mx.core.UIComponent class it.sephiroth.image extends UIComponent { public var addEventListener:Function; public var removeEventListener:Function; public var dispatchEvent:Function; public var loaded:Boolean var $mc:MovieClip var $url:String var $isPhotoGallery:Boolean function init(){ EventDispatcher.initialize(this); } function image(mc:MovieClip, url:String, isPhotoGallery:Boolean){ $mc = mc $url = url $isPhotoGallery = isPhotoGallery } private function load():Void { this.purge($mc) var holder:MovieClip = $mc.createEmptyMovieClip('holder', $mc.getNextHighestDepth()) var mcl:MovieClipLoader = new MovieClipLoader() var listener:Object = new Object() listener.target = this listener.onLoadInit = function(target:MovieClip){ this.target.dispatchEvent ({type:"complete", target: this.target}); var obj = { ga:100, gb:255, ra:100, rb:255, ba:100, bb:255, aa:0, ab:255 } var col:Color = new Color(target._parent) if($isPhotoGallery){ target._parent._alpha = 0 } target._parent.target = this.target target._parent.onEnterFrame = function(){ if($isPhotoGallery){ this._alpha += 5 if(this._alpha >= 100){ var depth = this.getDepth() if(this._parent.getInstanceAtDepth(depth-1)){ this._parent.getInstanceAtDepth(depth-1).unloadMovie() } delete this.onEnterFrame this.target.loaded = true this.target.dispatchEvent ({type:"complete", target:this.target}); } } else { obj.rb *= .9 obj.gb *= .9 obj.bb *= .9 obj.aa += 2 if(obj.aa >= 90 || obj.rb <= 5){ obj.aa = 100 obj.rb = 0 obj.gb = 0 obj.bb = 0 col.setTransform( obj ) delete this.onEnterFrame this.target.loaded = true this.target.dispatchEvent ({type:"transitionFinished", target: this.target}); } col.setTransform( obj ) } } target._parent.onEnterFrame(); } listener.onLoadError = function(target){ trace("onLoadError") this.target.loaded = true this.target.dispatchEvent ({type:"error", target: this.target}); } mcl.addListener(listener) mcl.loadClip($url, holder) this.loaded = false } public function purge(mc:MovieClip){ mc.holder.removeMovieClip() this.loaded = true } public function get movie(){ return $mc } }