Created
January 11, 2010 19:23
-
-
Save scottdavis/274502 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hubblesite.webprint | |
{ | |
import flash.display.Loader; | |
import flash.display.MovieClip; | |
import flash.events.Event; | |
import flash.events.EventDispatcher; | |
import flash.utils.ByteArray; | |
import mx.controls.Image; | |
import mx.core.Application; | |
import mx.events.FlexEvent; | |
import mx.managers.SystemManager; | |
public class LoadEmbededSwf extends EventDispatcher | |
{ | |
private var swf:Object; | |
public var loader:Loader = new Loader; | |
public var movie:MovieClip; | |
public var image:Image = new Image; | |
public var loaded:Boolean = false; | |
public static var LOADED:String = 'loaded'; | |
public function LoadEmbededSwf(embededSwf:Object) | |
{ | |
this.swf = embededSwf; | |
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.is_loaded); | |
loader.loadBytes(ByteArray(this.swf)); | |
} | |
private function is_loaded(e:Event) :void { | |
trace('[LoadEmbededSwf::swf is loaded]'); | |
e.currentTarget.content.addEventListener(FlexEvent.APPLICATION_COMPLETE, load_handlers); | |
this.movie = e.currentTarget.content as MovieClip; | |
this.movie.gotoAndStop(0); | |
this.image.source = this.movie; | |
this.loaded = true; | |
dispatchEvent(new Event(LoadEmbededSwf.LOADED)); | |
} | |
private function load_handlers(e:FlexEvent) :void { | |
var sysmgr:SystemManager = e.currentTarget as SystemManager; | |
var app:Application = sysmgr.application as Application; | |
trace('[LoadEmbededSwf::im here with a handle to the app!]'); | |
} | |
public static function insert(swf:Object, location:Object, callback:Function = null) :LoadEmbededSwf { | |
var temp:LoadEmbededSwf = new LoadEmbededSwf(swf); | |
temp.addEventListener(LoadEmbededSwf.LOADED, function() :void { | |
temp.insertInto(location); | |
if(callback) {callback();} | |
}); | |
return temp; | |
} | |
public function insertInto(location:Object) :void { | |
location.addChild(this.image); | |
} | |
public function pause() :void { | |
this.movie.pause(); | |
} | |
public function play() :void { | |
this.movie.play(); | |
} | |
public function gotoAndStop(int:uint) :void { | |
this.movie.gotoAndStop(int); | |
} | |
public function gotoAndPlay(int:uint) :void { | |
this.movie.gotoAndPlay(int); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment