Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: c2d6e03fa3
...
compare: c8b0a25004
Checking mergeability… Don't worry, you can still create the pull request.
  • 10 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
35 com/zehfernando/display/containers/CameraContainer.as
@@ -1,5 +1,4 @@
package com.zehfernando.display.containers {
-
import com.zehfernando.utils.console.log;
import flash.display.BitmapData;
@@ -304,7 +303,7 @@ package com.zehfernando.display.containers {
}
public function getNumValidCameras(): int {
- // Returns the number of valid cameras, after a autoSelectActiveCamera() call
+ // Returns the number of valid cameras, after a findActiveCameras() call
var c:int = 0;
for (var i:int = 0; i < validCameras.length; i++) {
if (validCameras[i]) c++;
@@ -338,5 +337,37 @@ package com.zehfernando.display.containers {
redrawSmoothing();
}
+ public function get muted(): Boolean {
+ return Boolean(_camera) ? _camera.muted : false;
+ }
+
+ public function get currentFPS(): Number {
+ return Boolean(_camera) ? _camera.currentFPS : 0;
+ }
+
+ public function get fps(): Number {
+ return Boolean(_camera) ? _camera.fps : 0;
+ }
+
+ public function get activityLevel(): Number {
+ return Boolean(_camera) ? _camera.activityLevel : 0;
+ }
+
+ public function get bandwidth(): int {
+ return Boolean(_camera) ? _camera.bandwidth : 0;
+ }
+
+ public function get cameraWidth(): int {
+ return Boolean(_camera) ? _camera.width : 0;
+ }
+
+ public function get cameraHeight(): int {
+ return Boolean(_camera) ? _camera.height : 0;
+ }
+
+ public function get cameraName(): String {
+ return Boolean(_camera) ? _camera.name : null;
+ }
+
}
}
View
224 com/zehfernando/display/containers/ImageWithAlphaContainer.as
@@ -0,0 +1,224 @@
+package com.zehfernando.display.containers {
+
+ import com.zehfernando.utils.console.log;
+
+ import flash.display.Bitmap;
+ import flash.display.BlendMode;
+ import flash.display.Loader;
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
+ import flash.events.ProgressEvent;
+ import flash.net.URLRequest;
+ import flash.system.LoaderContext;
+ /**
+ * @author zeh at zehfernando.com
+ */
+ public class ImageWithAlphaContainer extends DynamicDisplayAssetContainer {
+
+ // Constants
+ // Exception fault: SecurityError: Error #2123: Security sandbox violation: BitmapData.draw: http://fakehost.com/5GUM_COACHELLA2912/deploy/site/index.swf cannot access http://static.ak.fbcdn.net/rsrc.php/v1/yL/r/HsTZSDw4avx.gif?type=large. No policy files granted access.
+ public static const EVENT_SECURITY_SANDBOX_VIOLATION:String = "onSecuritySandboxViolation";
+
+ // Properties
+ protected var _isConnectionOpened:Boolean;
+ protected var _isConnectionOpenedAlpha:Boolean;
+
+ // Instances
+ protected var loader:Loader;
+ protected var loaderAlpha:Loader;
+
+ protected var loaderContainer:Sprite;
+
+ protected var _isLoadedImage:Boolean;
+ protected var _isLoadedAlpha:Boolean;
+
+ // ================================================================================================================
+ // CONSTRUCTOR ----------------------------------------------------------------------------------------------------
+
+ public function ImageWithAlphaContainer(__width:Number = 100, __height:Number = 100, __color:Number = 0x000000) {
+ super (__width, __height, __color);
+ }
+
+ // ================================================================================================================
+ // INTERNAL functions ---------------------------------------------------------------------------------------------
+
+ override public function dispose(): void {
+ if (_isLoading) {
+ if (_isConnectionOpened && !(_bytesLoaded > 0 && _bytesLoaded == _bytesTotal)) loader.close();
+ if (_isConnectionOpenedAlpha && !(_bytesLoaded > 0 && _bytesLoaded == _bytesTotal)) loader.close();
+ //loader.close();
+ }
+ if (_isLoadedImage) loader.unload();
+ if (_isLoadedAlpha) loaderAlpha.unload();
+
+ if (Boolean(loader)) {
+ removeLoaderEvents(loader);
+ loaderContainer.removeChild(loader);
+ loader = null;
+ }
+
+ if (Boolean(loaderAlpha)) {
+ removeLoaderEvents(loaderAlpha);
+ loaderContainer.removeChild(loaderAlpha);
+ loaderAlpha = null;
+ }
+
+ if (Boolean(loaderContainer)) {
+ contentHolder.removeChild(loaderContainer);
+ loaderContainer = null;
+ }
+
+ super.dispose();
+ }
+
+ protected function removeLoaderEvents(__loader:Loader): void {
+ __loader.contentLoaderInfo.removeEventListener(Event.OPEN, onLoadOpen);
+ __loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
+ __loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoadProgress);
+ __loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
+ }
+
+ override protected function applySmoothing(): void {
+ if (_isLoaded) {
+ try {
+ if (Boolean(loader.content)) Bitmap(loader.content).smoothing = _smoothing;
+ if (Boolean(loaderAlpha.content)) Bitmap(loaderAlpha.content).smoothing = _smoothing;
+ } catch (e:Error) {
+ // Error here - meaning it's probably trying to load content not allowed
+ dispatchEvent(new Event(EVENT_SECURITY_SANDBOX_VIOLATION));
+ trace ("Error when trying to access loader.content smoothing!");
+ }
+ }
+ }
+
+
+ // ================================================================================================================
+ // EVENT functions ------------------------------------------------------------------------------------------------
+
+ protected function onLoadOpen(e:Event = null): void {
+ if (e.currentTarget == loader.contentLoaderInfo) {
+ _isConnectionOpened = true;
+ } else {
+ _isConnectionOpenedAlpha = true;
+ }
+ }
+
+ protected function onLoadComplete(e:Event = null): void {
+
+ if (e.currentTarget == loader.contentLoaderInfo) {
+ _isLoadedImage = true;
+ _isConnectionOpened = false;
+ } else {
+ _isLoadedAlpha = true;
+ _isConnectionOpenedAlpha = false;
+ }
+
+ if (_isLoadedImage && _isLoadedAlpha) {
+ _isLoading = false;
+ _isLoaded = true;
+ try {
+ _contentWidth = loader.content.width;
+ _contentHeight = loader.content.height;
+ } catch (e:Error) {
+ // Error here - meaning it's probably trying to load content not allowed
+ _contentWidth = 100;
+ _contentHeight = 100;
+ updateCompletedLoadingStats();
+ removeLoaderEvents(loader);
+ removeLoaderEvents(loaderAlpha);
+ trace ("Error when trying to access loader.content width/height!");
+ dispatchEvent(new Event(EVENT_SECURITY_SANDBOX_VIOLATION));
+ return;
+ }
+ updateCompletedLoadingStats();
+ removeLoaderEvents(loader);
+ removeLoaderEvents(loaderAlpha);
+ redraw();
+ dispatchEvent(e);
+ }
+ }
+
+ protected function onLoadProgress(e:ProgressEvent = null): void {
+ //trace ("ImageContainer :: onLoadProgress :: " + e);
+ dispatchEvent(e);
+ if (!isNaN(_timeStartedLoading)) updateStartedLoadingStats();
+ _bytesLoaded = loader.contentLoaderInfo.bytesLoaded + loaderAlpha.contentLoaderInfo.bytesLoaded;
+ _bytesTotal = (loader.contentLoaderInfo.bytesTotal > 0 ? loader.contentLoaderInfo.bytesTotal : 50000) + (loaderAlpha.contentLoaderInfo.bytesTotal > 0 ? loaderAlpha.contentLoaderInfo.bytesTotal : 50000);
+ }
+
+ protected function onLoadError(e:IOErrorEvent = null): void {
+ trace ("ERROR :: ImageContainer :: onLoadError :: " + e);
+ _isLoading = false;
+
+ if (e.currentTarget == loader.contentLoaderInfo) {
+ _isConnectionOpened = false;
+ if (_isLoadedAlpha) loaderAlpha.unload();
+ } else {
+ _isConnectionOpenedAlpha = false;
+ if (_isLoadedImage) loader.unload();
+ }
+
+ _timeStartedLoading = NaN;
+ _isLoaded = false;
+ removeLoaderEvents(loader);
+ removeLoaderEvents(loaderAlpha);
+ dispatchEvent(e);
+ }
+
+
+ // ================================================================================================================
+ // PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
+
+ public function loadWithAlpha(__imageURL:String, __alphaURL:String): void {
+ if (!Boolean(__imageURL) || !Boolean(__alphaURL)) {
+ trace ("ImageContainer :: ERROR: tried loading image from null url ["+__imageURL+"] with alpha ["+__alphaURL+"]");
+ return;
+ }
+
+ super.load(__imageURL);
+
+ _isLoading = true;
+ _isConnectionOpened = false;
+ _isConnectionOpenedAlpha = false;
+ _isLoaded = false;
+ _isLoadedImage = false;
+ _isLoadedAlpha = false;
+
+ loaderContainer = new Sprite();
+ loaderContainer.blendMode = BlendMode.LAYER;
+ setAsset(loaderContainer);
+
+ loader = new Loader();
+
+ loader.contentLoaderInfo.addEventListener(Event.OPEN, onLoadOpen);
+ loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
+ loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
+ loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
+
+ loaderContainer.addChild(loader);
+
+ loaderAlpha = new Loader();
+
+ loaderAlpha.contentLoaderInfo.addEventListener(Event.OPEN, onLoadOpen);
+ loaderAlpha.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
+ loaderAlpha.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
+ loaderAlpha.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
+ loaderAlpha.blendMode = BlendMode.ALPHA;
+
+ loaderContainer.addChild(loaderAlpha);
+
+ var context:LoaderContext = new LoaderContext();
+ context.checkPolicyFile = true;
+
+ loader.load(new URLRequest(__imageURL), context);
+ loaderAlpha.load(new URLRequest(__alphaURL), context);
+ }
+
+ override public function unload():void {
+ super.unload();
+
+ loaderContainer = null;
+ }
+ }
+}
View
4 com/zehfernando/display/containers/YouTubeImageContainer.as
@@ -1,10 +1,10 @@
package com.zehfernando.display.containers {
- import flash.system.Security;
import com.zehfernando.net.apis.youtube.data.YouTubeVideo;
import com.zehfernando.net.apis.youtube.events.YouTubeServiceEvent;
import com.zehfernando.net.apis.youtube.services.YouTubeVideoInfoRequest;
- import flash.system.SecurityDomain;
+
+ import flash.system.Security;
/**
* @author zeh at zehfernando.com
View
18 com/zehfernando/display/templates/application/ApplicationFrame1Abstract.as
@@ -89,7 +89,7 @@ package com.zehfernando.display.templates.application {
frame2DataLoaded = false;
frame2DataLoadingPhase = 0;
- frame2DataLoadingWeight = 200;
+ frame2DataLoadingWeight = 10;
timeStartedLoading = getTimer();
sizeAfterPreloader = loaderInfo.bytesLoaded;
@@ -101,9 +101,9 @@ package com.zehfernando.display.templates.application {
// Debug stuff
if (AppUtils.isDebugSWF()) {
- var sg:StatGraph = new StatGraph(210);
- sg.alpha = 0.8;
- stage.addChild(sg);
+// var sg:StatGraph = new StatGraph(210);
+// sg.alpha = 0.8;
+// stage.addChild(sg);
// stage.addChild(new QuickButton("BG INTERFACE: PAUSE", 10, 100, function():void { Main.getInstance().pauseBackgroundInterface(); }, 150, 26));
// stage.addChild(new QuickButton("BG INTERFACE: RESUME", 10, 130, function():void { Main.getInstance().resumeBackgroundInterface(); }, 150, 26));
@@ -251,17 +251,15 @@ package com.zehfernando.display.templates.application {
// EXTEND THIS
}
- protected function hideLoadingInterface(): void {
+ protected function removeLoadingInterface(): void {
// EXTEND THIS
- removeLoadingInterface();
}
- protected function removeLoadingInterface(): void {
- // EXTEND THIS
+ protected function removeLoadingInterfaceAndShowFrame2(): void {
+ removeLoadingInterface();
showFrame2();
}
-
// ================================================================================================================
// EVENT functions ------------------------------------------------------------------------------------------------
@@ -403,7 +401,7 @@ package com.zehfernando.display.templates.application {
frame2.removeEventListener(ApplicationFrame2Event.INIT_COMPLETE, onFrame2InitComplete);
//showFrame2();
- hideLoadingInterface();
+ removeLoadingInterfaceAndShowFrame2();
}
}
}
View
364 com/zehfernando/localization/StringList.as
@@ -2,47 +2,37 @@ package com.zehfernando.localization {
import com.zehfernando.data.types.Color;
import com.zehfernando.utils.DateUtils;
+
+ import flash.events.EventDispatcher;
/**
* @author zeh at zehfernando.com
*/
- public class StringList {
+ public class StringList extends EventDispatcher {
-// Android:
-// <color name="color">#ffffff</color>
-// <dimen name="dimension">10px</dimen>
-// <drawable name="drawable">#ffffff</drawable>
-// <integer-array name="integer_array">
-// <item>1312</item>
-// </integer-array>
-// <item format="color" type="color" name="item">#ffffff</item>
-// <string name="string">0187390123</string>
-// <string-array name="string_array">
-// <item>lajsdhlas</item>
-// </string-array>
-// <style parent="asda" name="style_theme"></style>
/*
-
- <string>
- <color>
- <number>
- <boolean>
- <datetime>
+ <string name="myString" language="en,en-us">aaaa</string>
+ <color>#ffffff</color> <!-- Or any CSS-like value -->
+ <number>110.2</number>
+ <boolean>true</boolean>
+ <datetime>1980-01-01T00:00:00-06:00</datetime>
- <string-array>
+ <string-array><item>...</item></string-array>
<color-array>
<number-array>
<boolean-array>
<datetime-array>
- <group>
+ <group>...</group>
- <data>
+ <data><someXML/></data>
*/
-
// Constants
public static const LANGUAGE_LIST_SEPARATOR:String = ",";
public static const ID_HYERARCHY_SEPARATOR:String = "/";
+
+ // Static properties
+ protected static var lists:Vector.<StringList>;
// Value enums
protected static const VALUE_BOOLEAN_TRUE:String = "true";
@@ -55,8 +45,6 @@ package com.zehfernando.localization {
protected static const VALUE_COLOR_DEFAULT:String = "#000000";
protected static const VALUE_DATETIME_DEFAULT:String = "1980-01-01T00:00:00-06:00";
- protected static const VALUE_NOT_FOUND:String = "[null]"; // TODO: properly return null when this happens? or the string id itself?
-
// Type enums
protected static const TYPE_STRING:String = "string";
protected static const TYPE_STRING_ARRAY:String = "string-array";
@@ -73,29 +61,56 @@ package com.zehfernando.localization {
protected static const TYPE_ITEM:String = "item";
// Properties
- protected static var values:ValueGroup;
- protected static var currentLanguages:Vector.<String>; // Current language, ie, ["en", "en-us"]
+ protected var _name:String;
+ protected var values:ValueGroup; // Main group
+ protected var currentLanguages:Vector.<String>; // Current language chain, e.g. ["en", "en-us"]
// ================================================================================================================
- // STATIC CONSTRUCTOR ---------------------------------------------------------------------------------------------
+ // CONSTRUCTOR ----------------------------------------------------------------------------------------------------
+
+ public function StringList(__name:String = "") {
+ _name = __name;
+
+ values = new ValueGroup();
+
+ StringList.addList(this);
+ }
+
+ // ================================================================================================================
+ // STATIC functions -----------------------------------------------------------------------------------------------
- protected static function init(): void {
- // ValueGroup is not accessible on the actual static init block, so initialize it manually
- if (!Boolean(values)) {
- values = new ValueGroup();
+ {
+ lists = new Vector.<StringList>();
+ }
+
+ protected static function addList(__list:StringList): void {
+ if (lists.indexOf(__list) == -1) {
+ lists.push(__list);
}
}
- // ================================================================================================================
- // CONSTRUCTOR ----------------------------------------------------------------------------------------------------
+ protected static function removeList(__list:StringList): void {
+ if (lists.indexOf(__list) != -1) {
+ lists.splice(lists.indexOf(__list), 1);
+ }
+ }
+
+ public static function getList(__name:String = "", __canCreate:Boolean = true): StringList {
+ var i:int;
+ for (i = 0; i < lists.length; i++) {
+ if (lists[i].name == __name) return lists[i];
+ }
- public function StringList() {
- throw new Error("Instantiation not allowed");
+ // Not found
+ if (__canCreate) {
+ // Create a new, empty list
+ return new StringList();
+ }
+
+ // Error
+ return null;
}
- // ================================================================================================================
- // INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
-
protected static function getXMLAsItem(__item:XML): ValueNode {
// Converts XML data to a value node
var newItem:ValueNode;
@@ -109,6 +124,7 @@ package com.zehfernando.localization {
case TYPE_BOOLEAN:
case TYPE_COLOR:
case TYPE_DATETIME:
+ // String-based values are stored as string
newItem = new ValueString();
newItem.type = nodeName;
(newItem as ValueString).value = __item.toString();
@@ -118,18 +134,21 @@ package com.zehfernando.localization {
case TYPE_BOOLEAN_ARRAY:
case TYPE_COLOR_ARRAY:
case TYPE_DATETIME_ARRAY:
+ // Array-based values are stored as a list of strings
newItem = new ValueArray();
newItem.type = nodeName;
var subItems:XMLList = __item.child(TYPE_ITEM);
for (i = 0; i < subItems.length(); i++) {
- (newItem as ValueArray).items.push(String(subItems[i]));
+ (newItem as ValueArray).items.push((subItems[i] as XML).toString());
}
break;
case TYPE_DATA:
+ // Data values are stored as its XML source
newItem = new ValueXML();
(newItem as ValueXML).value = __item;
break;
case TYPE_GROUP:
+ // Groups (with subitems) are stored as a special type
newItem = getXMLListAsGroup(__item.children());
break;
default:
@@ -155,7 +174,7 @@ package com.zehfernando.localization {
protected static function getXMLListAsGroup(__items:XMLList): ValueGroup {
// Converts XML data to a value group
var newGroup:ValueGroup = new ValueGroup();
- newGroup.type = TYPE_GROUP; // TODO: this is redundant, remove?
+ newGroup.type = TYPE_GROUP; // This is a little bit redundant but consistent with how other types are treated
var i:int;
for (i = 0; i < __items.length(); i++) {
newGroup.items.push(getXMLAsItem(__items[i]));
@@ -164,6 +183,7 @@ package com.zehfernando.localization {
}
protected static function convertStringToType(__string:String, __type:String): * {
+ // Converts a string-based value to its specific value
switch(__type) {
case TYPE_STRING:
if (!Boolean(__string)) __string = VALUE_STRING_DEFAULT;
@@ -187,7 +207,50 @@ package com.zehfernando.localization {
return null;
}
- protected static function getProcessedStringInternal(__string:String, __languages:Vector.<String>): String {
+ protected static function convertStringArrayToType(__strings:Vector.<String>, __type:String): * {
+ // Converts a string-based array to its specific value array
+ var lst:Object;
+ var itemType:String;
+ var i:int;
+
+ switch(__type) {
+ case TYPE_STRING_ARRAY:
+ lst = new Vector.<String>();
+ itemType = TYPE_STRING;
+ break;
+ case TYPE_NUMBER_ARRAY:
+ lst = new Vector.<Number>();
+ itemType = TYPE_NUMBER;
+ break;
+ case TYPE_BOOLEAN_ARRAY:
+ lst = new Vector.<Boolean>();
+ itemType = TYPE_BOOLEAN;
+ break;
+ case TYPE_COLOR_ARRAY:
+ lst = new Vector.<Color>();
+ itemType = TYPE_COLOR;
+ break;
+ case TYPE_DATETIME_ARRAY:
+ lst = new Vector.<Date>();
+ itemType = TYPE_DATETIME;
+ break;
+ default:
+ trace ("StringList :: Error trying to convert array to node of type ["+String(__type)+"]");
+ return null;
+ break;
+ }
+
+ for (i = 0; i < __strings.length; i++) {
+ lst["push"](convertStringToType(__strings[i], itemType));
+ }
+
+ return lst;
+ }
+
+ // ================================================================================================================
+ // INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
+
+ protected function getProcessedStringInternal(__string:String, __languages:Vector.<String>): String {
// Returns a string with processed codes
// For example "this is an ${examples/example}!" returns "this is an EXAMPLE!" (where the value of examples/example in strings.xml is "EXAMPLE")
@@ -218,50 +281,21 @@ package com.zehfernando.localization {
// End text after last tag
newString += __string.substring(lastIndex, __string.length);
-// trace ("OUTPUT ============================ " + newString);
-
return newString;
}
- // ================================================================================================================
- // PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
-
- public static function setFromXML(__xml:XML): void {
- init();
-
- values.add(getXMLListAsGroup(__xml.children()));
- // TODO: read string data replacing unix/windows line feed?
- }
-
- public static function setCurrentLanguage(__language:String): void {
- setCurrentLanguages(__language);
- }
-
- public static function setCurrentLanguages(... __languages): void {
- currentLanguages = new Vector.<String>();
- for (var i:int = 0; i < __languages.length; i++) {
- currentLanguages.push(__languages[i]);
+ protected function getProcessedStringArrayInternal(__strings:Vector.<String>, __languages:Vector.<String>): Vector.<String> {
+ var i:int;
+ var newStrings:Vector.<String> = new Vector.<String>();
+
+ for (i = 0; i < __strings.length; i++) {
+ newStrings.push(getProcessedStringInternal(__strings[i], __languages));
}
- // TODO: add language change event listener
+
+ return newStrings;
}
- public static function getCurrentLanguages(): Vector.<String> {
- return currentLanguages.concat();
- }
-
- public static function setString(__id:String, __value:String): void {
- var vs:ValueString = new ValueString();
- vs.name = __id;
- vs.value = __value;
- vs.type = TYPE_STRING;
-
- var vg:ValueGroup = new ValueGroup();
- vg.items.push(vs);
-
- values.add(vg);
- }
-
- public static function getValue(__id:String, ... __languages): * {
+ protected function getValue(__id:String, __languages:Array): * {
var i:int;
// Get the full path to the value name
@@ -274,7 +308,7 @@ package com.zehfernando.localization {
langsToUse = new Vector.<String>();
for (i = 0; i < __languages.length; i++) langsToUse.push(__languages[i]);
} else {
- langsToUse = StringList.getCurrentLanguages();
+ langsToUse = getCurrentLanguages();
}
var node:ValueNode = values.getValueNodeByNames(names, langsToUse);
@@ -284,148 +318,109 @@ package com.zehfernando.localization {
if (node is ValueString) {
// Any standard string node
return convertStringToType(getProcessedStringInternal((node as ValueString).value, langsToUse), node.type);
-
} else if (node is ValueArray) {
// Any array node
- var lst:*;
- var itemType:String;
-
- switch(node.type) {
- case TYPE_STRING_ARRAY:
- lst = new Vector.<String>();
- itemType = TYPE_STRING;
- break;
- case TYPE_NUMBER_ARRAY:
- lst = new Vector.<Number>();
- itemType = TYPE_NUMBER;
- break;
- case TYPE_BOOLEAN_ARRAY:
- lst = new Vector.<Boolean>();
- itemType = TYPE_BOOLEAN;
- break;
- case TYPE_COLOR_ARRAY:
- lst = new Vector.<Color>();
- itemType = TYPE_COLOR;
- break;
- case TYPE_DATETIME_ARRAY:
- lst = new Vector.<Date>();
- itemType = TYPE_DATETIME;
- break;
- default:
- trace ("StringList :: Error trying to convert array to node of type ["+node.type+"]");
- return null;
- break;
- }
-
- for (i = 0; i < (node as ValueArray).items.length; i++) {
- lst["push"](convertStringToType(getProcessedStringInternal((node as ValueArray).items[i], langsToUse), itemType));
- }
-
- return lst;
+ return convertStringArrayToType(getProcessedStringArrayInternal((node as ValueArray).items, langsToUse), node.type);
} else if (node is ValueXML) {
// Any XML node
return (node as ValueXML).value;
-
} else if (!Boolean(node)) {
// Not found at all
- return VALUE_NOT_FOUND;
+ return null;
}
trace ("StringList :: Error trying to read node [" + node + "] of type ["+node.type+"]");
return null;
}
- public static function getString(__id:String, ... __languages): String {
- var args:Array = [__id];
- args = args.concat(__languages);
+ // ================================================================================================================
+ // PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
- return getValue.apply(null, args);
+ public function setFromXML(__xml:XML): void {
+ values.add(getXMLListAsGroup(__xml.children()));
+ // TODO: read string data replacing unix/windows line feed?
}
- public static function getNumber(__id:String, ... __languages): Number {
- var args:Array = [__id];
- args = args.concat(__languages);
+ public function setCurrentLanguages(... __languages): void {
+ currentLanguages = new Vector.<String>();
+ for (var i:int = 0; i < __languages.length; i++) {
+ currentLanguages.push(__languages[i]);
+ }
- return getValue.apply(null, args);
+ dispatchEvent(new StringListEvent(StringListEvent.CHANGED_LANGUAGE));
+ }
+
+ public function getCurrentLanguages(): Vector.<String> {
+ return currentLanguages.concat();
+ }
+
+// public function setString(__id:String, __value:String): void {
+// var vs:ValueString = new ValueString();
+// vs.name = __id;
+// vs.value = __value;
+// vs.type = TYPE_STRING;
+//
+// var vg:ValueGroup = new ValueGroup();
+// vg.items.push(vs);
+//
+// values.add(vg);
+// }
+
+ public function getString(__id:String, ... __languages): String {
+ return getValue(__id, __languages);
}
+ public function getNumber(__id:String, ... __languages): Number {
+ return getValue(__id, __languages);
+ }
- public static function getXML(__id:String, ... __languages): XML {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args);
+ public function getBoolean(__id:String, ... __languages): Boolean {
+ return getValue(__id, __languages);
}
- public static function getProcessedString(__text:String, ... __languages): String {
+ public function getColor(__id:String, ... __languages): uint {
+ return getValue(__id, __languages);
+ }
+
+ public function getXML(__id:String, ... __languages): XML {
+ return getValue(__id, __languages);
+ }
+
+ public function getProcessedString(__text:String, ... __languages): String {
var langsToUse:Vector.<String>;
var i:int;
if (Boolean(__languages) && __languages.length > 0) {
langsToUse = new Vector.<String>();
for (i = 0; i < __languages.length; i++) langsToUse.push(__languages[i]);
} else {
- langsToUse = StringList.getCurrentLanguages();
+ langsToUse = getCurrentLanguages();
}
return getProcessedStringInternal(__text, langsToUse);
}
- public static function getBoolean(__id:String, ... __languages): Boolean {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args);
+ public function getStringArray(__id:String, ... __languages): Vector.<String> {
+ return getValue(__id, __languages);
}
- public static function getColor(__id:String, ... __languages): int {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args);
+ public function getNumberArray(__id:String, ... __languages): Vector.<Number> {
+ return getValue(__id, __languages);
}
- public static function getStringArray(__id:String, ... __languages): Vector.<String> {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args) as Vector.<String>;
+ public function getBooleanArray(__id:String, ... __languages): Vector.<Boolean> {
+ return getValue(__id, __languages);
}
- public static function getNumberArray(__id:String, ... __languages): Vector.<Number> {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args) as Vector.<Number>;
+ public function getColorArray(__id:String, ... __languages): Vector.<uint> {
+ return getValue(__id, __languages);
}
- public static function getBooleanArray(__id:String, ... __languages): Vector.<Boolean> {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args) as Vector.<Boolean>;
- }
+ // ================================================================================================================
+ // ACCESSOR functions ---------------------------------------------------------------------------------------------
- public static function getColorArray(__id:String, ... __languages): Vector.<uint> {
- var args:Array = [__id];
- args = args.concat(__languages);
-
- return getValue.apply(null, args) as Vector.<uint>;
+ public function get name(): String {
+ return _name;
}
-
-// public static function filter(__txt:String, __language:String = null): String {
-// // If a string starts with "##", gets from list; if not, uses original
-// if (Boolean(__txt) && __txt.substr(0, 2) == "##") {
-// var st:String = StringList.getString(__txt.substr(1), __language);
-// if (st == StringListItem.NULL_STRING) {
-// return "["+__txt+"]";
-// } else {
-// return st;
-// }
-// } else {
-// return __txt;
-// }
-// return "";
-// }
}
}
@@ -522,11 +517,11 @@ class ValueGroup extends ValueNode {
// Public functions
public function getValueNodeByNames(__names:Vector.<String>, __languages:Vector.<String>): ValueNode {
// Returns a value given its name path and languages
- // Same as StringList.getValue(), but with pre-processed parameters
+ // Same as StringList.getValue(), but with pre-processed parameters (split)
var i:int, j:int;
- // Looks for all languages, one by one
+ // Looks for the string in all languages, one at a time
for (i = 0; i < __languages.length; i++) {
// Looks for all items
for (j = 0; j < items.length; j++) {
@@ -542,8 +537,7 @@ class ValueGroup extends ValueNode {
}
}
- // Not found, try a value with no language
- // TODO: redundant, refactor this
+ // Not found, try to find a value with no language
for (i = 0; i < items.length; i++) {
if (items[i].name == __names[0] && items[i].languages.length == 0) {
if (items[i] is ValueGroup) {
View
27 com/zehfernando/localization/StringListEvent.as
@@ -0,0 +1,27 @@
+package com.zehfernando.localization {
+
+ import flash.events.Event;
+ /**
+ * @author zeh at zehfernando.com
+ */
+ public class StringListEvent extends Event {
+
+ // Constants
+ public static const CHANGED_LANGUAGE:String = "onChangedLanguage";
+
+ // ================================================================================================================
+ // CONSTRUCTOR ----------------------------------------------------------------------------------------------------
+
+ public function StringListEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
+ super(type, bubbles, cancelable);
+ }
+
+ // ================================================================================================================
+ // PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
+
+ override public function clone(): Event {
+ return new StringListEvent(type, bubbles, cancelable);
+ }
+
+ }
+}
View
16 com/zehfernando/navigation/SpriteNavigator.as
@@ -26,6 +26,7 @@ package com.zehfernando.navigation {
//public static var siteTitle:String = "siteTitle";
public static var titleSeparator:String = " - ";
+ public static var useLastTitleOnly:Boolean = false; // TODO: make this a getter/setter
protected static var currentLocationInternal:Vector.<String>; // List of stubs
@@ -389,7 +390,20 @@ package com.zehfernando.navigation {
}
public static function getTitle(): String {
- return getLocationTitles().join(titleSeparator);
+ var titles:Vector.<String> = getLocationTitles();
+ var lastTitle:String = "";
+
+ // Get last title that is not empty
+ var i:int = titles.length - 1;
+ while (i >= 0) {
+ if (Boolean(titles[i])) {
+ lastTitle = titles[i];
+ break;
+ }
+ i--;
+ }
+
+ return useLastTitleOnly ? lastTitle : titles.join(titleSeparator);
}
/*
View
11 com/zehfernando/net/assets/AssetLibrary.as
@@ -51,10 +51,7 @@ package com.zehfernando.net.assets {
// STATIC functions -----------------------------------------------------------------------------------------------
protected static function addLibrary(__library:AssetLibrary): void {
-
- if (!Boolean(libraries)) {
- libraries = new Vector.<AssetLibrary>();
- }
+ if (!Boolean(libraries)) libraries = new Vector.<AssetLibrary>();
if (libraries.indexOf(__library) == -1) {
libraries.push(__library);
@@ -62,10 +59,7 @@ package com.zehfernando.net.assets {
}
protected static function removeLibrary(__library:AssetLibrary): void {
-
- if (!Boolean(libraries)) {
- libraries = new Vector.<AssetLibrary>();
- }
+ if (!Boolean(libraries)) libraries = new Vector.<AssetLibrary>();
if (libraries.indexOf(__library) != -1) {
libraries.splice(libraries.indexOf(__library), 1);
@@ -73,7 +67,6 @@ package com.zehfernando.net.assets {
}
public static function getLibrary(__name:String = ""): AssetLibrary {
- // Use object list instead?
var i:int;
for (i = 0; i < libraries.length; i++) {
if (libraries[i].name == __name) return libraries[i];
View
121 com/zehfernando/net/loaders/VideoLoader.as
@@ -1,7 +1,10 @@
package com.zehfernando.net.loaders {
+ import com.zehfernando.data.serialization.json.JSON;
import com.zehfernando.utils.MathUtils;
+ import com.zehfernando.utils.console.debug;
import com.zehfernando.utils.console.log;
+ import com.zehfernando.utils.console.warn;
import flash.display.Sprite;
import flash.events.Event;
@@ -58,6 +61,12 @@ package com.zehfernando.net.loaders {
protected var lastCuePoint:Object;
protected var _request:URLRequest;
+
+ protected var resumeAfterMetaDataLoad:Boolean;
+ protected var pauseAfterMetaDataLoad:Boolean;
+ protected var isPlayingToForceMetaDataLoad:Boolean;
+ protected var previousSoundTransform:SoundTransform;
+ protected var timeStartedWaitingForMetaData:int;
// ================================================================================================================
// PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
@@ -72,6 +81,8 @@ package com.zehfernando.net.loaders {
_isLoading = false;
_isLoaded = false;
+ timeStartedWaitingForMetaData = 0;
+
_netConnection = new NetConnection();
_netConnection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onNetError);
@@ -121,7 +132,31 @@ package com.zehfernando.net.loaders {
removeEventListener(Event.ENTER_FRAME, onEnterFrameMonitorTime);
}
}
-
+
+ protected function startPlayingToForceMetaDataLoad(): void {
+ if (!isPlayingToForceMetaDataLoad) {
+ debug("Started waiting for forced metadata load");
+ isPlayingToForceMetaDataLoad = true;
+ previousSoundTransform = _netStream.soundTransform;
+ _netStream.soundTransform = new SoundTransform(0, 0);
+ _netStream.resume();
+ //seek(1);
+ }
+ }
+
+ protected function stopPlayingToForceMetaDataLoad(): void {
+ if (isPlayingToForceMetaDataLoad) {
+ debug("Stopped waiting for forced metadata load");
+ isPlayingToForceMetaDataLoad = false;
+ seek(0);
+ _netStream.pause();
+ _netStream.soundTransform = previousSoundTransform;
+ previousSoundTransform = null;
+
+ //if (pauseAfterMetaDataLoad) pause();
+ //if (resumeAfterMetaDataLoad) resume();
+ }
+ }
// ================================================================================================================
// EVENT INTERFACE ------------------------------------------------------------------------------------------------
@@ -137,6 +172,14 @@ package com.zehfernando.net.loaders {
dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.RECEIVED_XMP_DATA));
}
+ public function onTextData(__newData:Object):void {
+ log ("##### TEXT DATA : " + JSON.encode(__newData));
+ }
+
+ public function onImageData(__newData:Object):void {
+ log ("##### IMAGE DATA : " + JSON.encode(__newData));
+ }
+
public function onMetaData(__newData:Object):void {
for (var iis:String in __newData) {
//Log.echo(" --> " + iis + " = " + __newData[iis]);
@@ -144,8 +187,12 @@ package com.zehfernando.net.loaders {
}
//log(_request.url + " METADATA ==============> " + JSON.encode(_metaData));
+
+ //log (">>> meta data received");
_hasMetaData = true;
+ stopPlayingToForceMetaDataLoad();
+
dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.RECEIVED_METADATA));
//if (_isLoading) onEnterFrameMonitorLoading(null);
@@ -411,7 +458,7 @@ package com.zehfernando.net.loaders {
dispatchEvent(new Event(Event.COMPLETE));
}
-
+
protected function onEnterFrameMonitorLoading(e:Event): void {
// Some load progress has been made
@@ -426,15 +473,44 @@ package com.zehfernando.net.loaders {
onLoadProgress();
if (bytesLoaded > 0) {
- if (bytesTotal > 0 && bytesLoaded >= bytesTotal && _hasMetaData) {
- // Completed loading
- onLoadComplete();
+ if (bytesTotal > 0 && bytesLoaded >= bytesTotal) {
+ if (_hasMetaData) {
+ // Completed loading
+ if (isPlayingToForceMetaDataLoad) {
+ debug("Received metadata later");
+ stopPlayingToForceMetaDataLoad();
+ }
+ debug("Finished loading");
+ onLoadComplete();
+ } else {
+ // Fix for videos that complete loading without onMetaData dispatched
+ if (!isPlayingToForceMetaDataLoad) {
+ if (timeStartedWaitingForMetaData == 0) {
+ debug("Completed loading but doesn't have metadata yet! Waiting some more");
+ timeStartedWaitingForMetaData = getTimer();
+ } else {
+ if (getTimer() > timeStartedWaitingForMetaData + 750) {
+ warn("Too much time passed, forcing video playback");
+ startPlayingToForceMetaDataLoad();
+ }
+ }
+ }
+ }
}
}
}
protected function onEnterFrameMonitorTime(e:Event): void {
- dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.TIME_CHANGE));
+ if (!isPlayingToForceMetaDataLoad) {
+ dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.TIME_CHANGE));
+ }
+ }
+
+ protected function onPlayStatus(event:NetStatusEvent):void {
+ log ("##### PLAY STATUS : " + event.info["code"]);
+ // NetStream.Play.Switch
+ // NetStream.Play.Complete
+ // NetStream.Play.TransitionComplete
}
protected function onNetStatus(event:NetStatusEvent):void {
@@ -470,8 +546,8 @@ package com.zehfernando.net.loaders {
case "NetStream.Play.Start":
// Apparently this only works with streaming netstreams?
//trace ("netstream.play.start " + _contentURL);
- startMonitoringTime();
- dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.PLAY_START));
+ startMonitoringTime();
+ dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.PLAY_START));
break;
case "NetStream.Buffer.Empty":
dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.BUFFER_EMPTY));
@@ -542,17 +618,34 @@ package com.zehfernando.net.loaders {
public function resume(): void {
if (_hasVideo) {
- _netStream.resume();
- startMonitoringTime();
- dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.RESUME));
+ //log(">>>>>>>>>>>>>>> resume");
+ //logStackTrace();
+ if (!_hasMetaData || isPlayingToForceMetaDataLoad) {
+ resumeAfterMetaDataLoad = true;
+ pauseAfterMetaDataLoad = false;
+ } else {
+ resumeAfterMetaDataLoad = false;
+ pauseAfterMetaDataLoad = false;
+ _netStream.resume();
+ startMonitoringTime();
+ dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.RESUME));
+ }
}
}
public function pause(): void {
if (_hasVideo) {
- _netStream.pause();
- stopMonitoringTime();
- dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.PAUSE));
+ //log(">>>>>>>>>>>>>>> pause");
+ if (!_hasMetaData || isPlayingToForceMetaDataLoad) {
+ resumeAfterMetaDataLoad = false;
+ pauseAfterMetaDataLoad = true;
+ } else {
+ resumeAfterMetaDataLoad = false;
+ pauseAfterMetaDataLoad = false;
+ _netStream.pause();
+ stopMonitoringTime();
+ dispatchEvent(new VideoLoaderEvent(VideoLoaderEvent.PAUSE));
+ }
}
}
View
24 com/zehfernando/utils/console/Console.as
@@ -3,6 +3,7 @@ package com.zehfernando.utils.console {
import com.zehfernando.utils.AppUtils;
import com.zehfernando.utils.DebugUtils;
+ import flash.display.Sprite;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.text.TextField;
@@ -18,6 +19,8 @@ package com.zehfernando.utils.console {
public static const PARAM_CLASS_NAME:String = "[[class]]";
public static const PARAM_FUNCTION_NAME:String = "[[function]]";
public static const PARAM_OUTPUT:String = "[[output]]";
+ public static const PARAM_CURRENT_FRAME:String = "[[current-frame]]";
+ public static const PARAM_CURRENT_FRAME_FORMAT:String = "00000";
public static const PARAM_TIME_NAME:String = "[[time-name]]";
public static const PARAM_TIME_VALUE:String = "[[time-value]]";
public static const PARAM_GROUP_NAME:String = "[[group]]";
@@ -25,8 +28,8 @@ package com.zehfernando.utils.console {
public static const LOG_STATE_OFF:String = "off";
public static const LOG_STATE_ON:String = "on";
- public static const ECHO_FORMAT_FULL:String = PARAM_PACKAGE_NAME + "." + PARAM_CLASS_NAME + "." + PARAM_FUNCTION_NAME + "() :: " + PARAM_OUTPUT;
- public static const ECHO_FORMAT_SHORT:String = PARAM_CLASS_NAME + "." + PARAM_FUNCTION_NAME + "() :: " + PARAM_OUTPUT;
+ public static const ECHO_FORMAT_FULL:String = "[" + PARAM_CURRENT_FRAME + "] " + PARAM_PACKAGE_NAME + "." + PARAM_CLASS_NAME + "." + PARAM_FUNCTION_NAME + "() :: " + PARAM_OUTPUT;
+ public static const ECHO_FORMAT_SHORT:String = "[" + PARAM_CURRENT_FRAME + "] " + PARAM_CLASS_NAME + "." + PARAM_FUNCTION_NAME + "() :: " + PARAM_OUTPUT;
public static const TIME_FORMAT:String = PARAM_TIME_NAME + ": " + PARAM_TIME_VALUE + "ms";
@@ -69,6 +72,9 @@ package com.zehfernando.utils.console {
protected static var timeTable:Object; // Named array of ints
protected static var groups:Vector.<String>;
+
+ protected static var currentFrame:int;
+ protected static var frameCounter:Sprite;
// http://getfirebug.com/logging
@@ -82,8 +88,13 @@ package com.zehfernando.utils.console {
logStates = [];
+ currentFrame = 0;
+
timeTable = {};
groups = new Vector.<String>();
+
+ frameCounter = new Sprite();
+ frameCounter.addEventListener(Event.ENTER_FRAME, onEnterFrameCounter);
}
@@ -123,8 +134,10 @@ package com.zehfernando.utils.console {
if (logStates[className] == LOG_STATE_OFF) return;
var currCall:Vector.<String> = DebugUtils.getCurrentCallStack()[3 + __callStackOffset]; // Package, class, function
+ var currFrame:String = (PARAM_CURRENT_FRAME_FORMAT + currentFrame.toString(10)).substr(-PARAM_CURRENT_FRAME_FORMAT.length, PARAM_CURRENT_FRAME_FORMAT.length);
var output:String = echoFormat;
+ output = output.split(PARAM_CURRENT_FRAME).join(currFrame);
output = output.split(PARAM_PACKAGE_NAME).join(currCall[0]);
output = output.split(PARAM_CLASS_NAME).join(currCall[1]);
output = output.split(PARAM_FUNCTION_NAME).join(currCall[2]);
@@ -200,6 +213,13 @@ package com.zehfernando.utils.console {
return packageName + "::" + className;
}
+ // ================================================================================================================
+ // EVENT INTERFACE ------------------------------------------------------------------------------------------------
+
+ protected static function onEnterFrameCounter(e:Event): void {
+ currentFrame++;
+ }
+
// ================================================================================================================
// PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
View
13 com/zehfernando/utils/tracking/GAUtils.as
@@ -1,10 +1,9 @@
package com.zehfernando.utils.tracking {
- import com.zehfernando.utils.console.log;
+ import com.zehfernando.utils.console.debug;
import flash.external.ExternalInterface;
-
/**
* @author Zeh Fernando
*/
@@ -42,7 +41,7 @@ package com.zehfernando.utils.tracking {
_verbose = true;
_simulated = false;
- if (_verbose) log ("Initialized :: verbose set to ["+_verbose+"] and simulated set to ["+_simulated+"]");
+ if (_verbose) debug ("Initialized :: verbose set to ["+_verbose+"] and simulated set to ["+_simulated+"]");
}
@@ -52,12 +51,12 @@ package com.zehfernando.utils.tracking {
// TODO: test for presence of tracking object?
public static function trackPageView(__url:String): void {
- if (_verbose) log ("[" + __url + "]");
+ if (_verbose) debug ("[" + __url + "]");
if (!_simulated) ExternalInterface.call("function(__url){_gaq.push(['_trackPageview', __url]);}", __url);
}
public static function trackEvent(__category:String, __action:String, __label:String = null, __value:Number = 0): void {
- if (_verbose) log ("Category: ["+__category+"] Action:["+__action+"] Label:["+__label+"] Value:["+__value+"]");
+ if (_verbose) debug ("Category: ["+__category+"] Action:["+__action+"] Label:["+__label+"] Value:["+__value+"]");
if (!_simulated) ExternalInterface.call("function(__category, __action, __label, __value){_gaq.push(['_trackEvent', __category, __action, __label, __value]);}", __category, __action, __label, __value);
//("Videos", "Video Load Time", "Gone With the Wind", downloadTime);
//("Videos", "Play", "Gone With the Wind");
@@ -97,7 +96,7 @@ package com.zehfernando.utils.tracking {
public static function set simulated(__value:Boolean): void {
if (_simulated != __value) {
_simulated = __value;
- log("simulated is " + _simulated);
+ debug("simulated is " + _simulated);
}
}
@@ -107,7 +106,7 @@ package com.zehfernando.utils.tracking {
public static function set verbose(__value:Boolean): void {
if (_verbose != __value) {
_verbose = __value;
- log("verbose is " + _verbose);
+ debug("verbose is " + _verbose);
}
}
}

No commit comments for this range

Something went wrong with that request. Please try again.