Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e52e8d1
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
LoaderTest.swf | ||
LoaderTest.zip |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | ||
|
||
<head> | ||
<title>LoaderTest</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | ||
<script type="text/javascript" src="swfobject.js"></script> | ||
<script type="text/javascript"> | ||
function test(method) { | ||
url = document.getElementById("url").value; | ||
swf = "LoaderTest.swf?method=" + escape(method) + "&url=" + escape(url); | ||
swfobject.embedSWF(swf, "loadArea", "800", "600", "9.0.0"); | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<form> | ||
<table> | ||
<tr> | ||
<td>Game URL</td> | ||
<td><input id="url" type="text" name="url" size="80" value="http://games.mochiads.com/c/g/bloons/bloons.swf" /></td> | ||
</tr> | ||
<tr> | ||
<td>Load method</td> | ||
<td> | ||
<input type="submit" value="Loader:load()" onclick="test('load'); return false" /> | ||
<input type="submit" value="Loader:loadBytes()" onclick="test('loadBytes'); return false" /> | ||
</td> | ||
</tr> | ||
</table> | ||
</form> | ||
|
||
<hr /> | ||
|
||
<div id="loadArea"> | ||
<p>[SWF will go here]</p> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.