diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e12705 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +LoaderTest.swf +LoaderTest.zip diff --git a/LoaderTest.as b/LoaderTest.as new file mode 100644 index 0000000..4fa7204 --- /dev/null +++ b/LoaderTest.as @@ -0,0 +1,123 @@ +/* Copyright 2011 Mochi Media, Inc. */ + +package { + import flash.display.*; + import flash.events.*; + import flash.net.*; + import flash.utils.*; + import flash.system.*; + + public class LoaderTest extends Sprite { + private var url:String = loaderInfo.parameters["url"]; + private var method:String = loaderInfo.parameters["method"]; + + private var loader:Loader = new Loader(); + private var bytesLoader:URLLoader = new URLLoader(); + + public function LoaderTest() { + trace("[LoaderTest] started"); + + Security.allowInsecureDomain("*"); + + bytesLoader.dataFormat = URLLoaderDataFormat.BINARY; + if (method == "load") + doLoad(); + else if (method == "loadBytes") + doLoadBytes(); + else { + trace("[LoaderTest] unknown method '" + method + "'; " + + "defaulting to 'load'"); + doLoad(); + } + addChild(loader); + } + + private function doLoad():void { + trace("[LoaderTest] doLoad called"); + loader.contentLoaderInfo.addEventListener(Event.INIT, onInit); + loader.load(new URLRequest(url)); + } + + private function doLoadBytes():void { + trace("[LoaderTest] doLoadBytes called"); + setupProgressBar(); + bytesLoader.addEventListener(ProgressEvent.PROGRESS, onProgress); + bytesLoader.addEventListener(Event.COMPLETE, onComplete); + bytesLoader.load(new URLRequest(url)); + } + + private function onProgress(ev:ProgressEvent):void { + trace("[LoaderTest] onProgress called"); + innerBar.scaleX = ev.bytesLoaded / ev.bytesTotal; + } + + private function onComplete(ev:Event):void { + trace("[LoaderTest] onComplete called"); + progressBar.visible = false; + loader.contentLoaderInfo.addEventListener(Event.INIT, onInit); + loader.loadBytes(bytesLoader.data); + } + + private function onInit(ev:Event):void { + trace("[LoaderTest] onInit called"); + try { + var rect:Shape = new Shape(); + var g:Graphics = rect.graphics; + g.beginFill(0xFFFFFF); + g.drawRect(0, 0, loader.contentLoaderInfo.width, loader.contentLoaderInfo.height); + g.endFill(); + loader.mask = rect; + } catch (error:Error) { + trace("[LoaderTest] couldn't set SWF mask"); + } + + try { + stage.frameRate = loader.contentLoaderInfo.frameRate; + } catch (error:Error) { + trace("[LoaderTest] couldn't adjust stage frame rate"); + } + } + + private var progressBar:Sprite; + private var innerBar:Shape; + + private function setupProgressBar():void { + var outerBar:Shape; + var hilight:Shape; + var g:Graphics; + + var w:uint = 800; + var h:uint = 600; + var padX:uint = 50; + var barHeight:uint = 10; + + outerBar = new Shape(); + g = outerBar.graphics; + g.beginFill(0xE6B873); + g.drawRect(0, 0, w - 2 * padX, barHeight); + g.endFill(); + + innerBar = new Shape(); + g = innerBar.graphics; + g.beginFill(0x806640); + g.drawRect(0, 0, w - 2 * padX, barHeight); + g.endFill(); + + hilight = new Shape(); + g = hilight.graphics; + g.lineStyle(0, 0xBF8630); + g.drawRect(0, 0, w - 2 * padX, barHeight); + + progressBar = new Sprite(); + progressBar.addChild(outerBar); + progressBar.addChild(innerBar); + progressBar.addChild(hilight); + + innerBar.scaleX = 0; + + progressBar.x = padX; + progressBar.y = (h - barHeight) / 2; + addChild(progressBar); + } + } +} diff --git a/LoaderTest.html b/LoaderTest.html new file mode 100644 index 0000000..8e6e8f4 --- /dev/null +++ b/LoaderTest.html @@ -0,0 +1,41 @@ + + + + + LoaderTest + + + + + + +
+ + + + + + + + + +
Game URL
Load method + + +
+
+ +
+ +
+

[SWF will go here]

+
+ + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a7957f1 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +MXMLC := mxmlc +FDB := fdb + +ZIP_SRC := Makefile LoaderTest.as LoaderTest.swf LoaderTest.html swfobject.js +TARGETS := LoaderTest.swf LoaderTest.zip + +.PHONY: all test clean + +all: $(TARGETS) + +clean: + rm -f $(TARGETS) + +test: all + $(FDB) LoaderTest.html + +LoaderTest.swf: LoaderTest.as + $(MXMLC) -default-background-color 0xCFD4E6 \ + -default-size 800 600 \ + -default-frame-rate 30 \ + -target-player 10 \ + -debug LoaderTest.as + +LoaderTest.zip: $(ZIP_SRC) + zip $@ $(ZIP_SRC) diff --git a/swfobject.js b/swfobject.js new file mode 100644 index 0000000..c383123 --- /dev/null +++ b/swfobject.js @@ -0,0 +1,5 @@ +/* SWFObject v2.0 + Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis + This software is released under the MIT License +*/ +var swfobject=function(){var Z="undefined",P="object",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",W="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,T=null,S=false,C=false;var a=function(){var l=typeof g.getElementById!=Z&&typeof g.getElementsByTagName!=Z&&typeof g.createElement!=Z&&typeof g.appendChild!=Z&&typeof g.replaceChild!=Z&&typeof g.removeChild!=Z&&typeof g.cloneNode!=Z,t=[0,0,0],n=null;if(typeof N.plugins!=Z&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=Z){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var e=function(){if(!a.w3cdom){return }J(I);if(a.ie&&a.win){try{g.write("