├── com └── zehfernando │ ├── utils │ ├── console │ │ ├── logOn.as │ │ ├── logOff.as │ │ ├── log.as │ │ ├── debug.as │ │ ├── error.as │ │ ├── info.as │ │ ├── warn.as │ │ └── logStackTrace.as │ ├── getTimerUInt.as │ ├── ArrayUtils.as │ ├── NumberUtils.as │ ├── RandomGenerator.as │ ├── SocialSharer.as │ ├── tracking │ │ ├── DARTUtils.as │ │ └── ComscoreUtils.as │ ├── RenderUtils.as │ └── VectorUtils.as │ ├── display │ ├── interfaces │ │ └── IDisposable.as │ ├── components │ │ └── text │ │ │ ├── TextSpriteAlign.as │ │ │ ├── EditableTextSpriteEvent.as │ │ │ ├── RichTextSpriteEvent.as │ │ │ └── UndoManager.as │ ├── decorators │ │ ├── AbstractDecorator.as │ │ └── BlurDecorator.as │ ├── templates │ │ ├── application │ │ │ ├── events │ │ │ │ └── ApplicationFrame2Event.as │ │ │ └── ApplicationFrame2Abstract.as │ │ └── videoplayer │ │ │ └── events │ │ │ ├── VideoPanelSeekEvent.as │ │ │ ├── VideoPanelVolumeEvent.as │ │ │ ├── VideoPanelEvent.as │ │ │ └── VideoPlayerEvent.as │ ├── debug │ │ ├── statgraph │ │ │ ├── TotalMemoryDataPoint.as │ │ │ ├── PrivateMemoryDataPoint.as │ │ │ ├── FPSDataPoint.as │ │ │ ├── CustomDataPoint.as │ │ │ └── MSDataPoint.as │ │ ├── QuickButtonPanel.as │ │ └── QuickButton.as │ ├── utils │ │ └── getRealBounds.as │ ├── progressbars │ │ ├── RectangleProgressBar.as │ │ ├── CircularProgressBar.as │ │ └── AbstractProgressBar.as │ ├── shapes │ │ ├── PointMarker.as │ │ ├── Triangle.as │ │ ├── Circle.as │ │ ├── BoxMarker.as │ │ └── Box.as │ ├── containers │ │ ├── IVideoContainer.as │ │ └── YouTubeImageContainer.as │ ├── drawPlane.as │ ├── ImageAnalyzer.as │ └── abstracts │ │ ├── ResizableSprite.as │ │ └── ButtonSprite.as │ ├── net │ ├── apis │ │ ├── parse │ │ │ ├── ParseConstants.as │ │ │ ├── events │ │ │ │ └── ParseServiceEvent.as │ │ │ └── services │ │ │ │ ├── ParseObjectPostRequest.as │ │ │ │ └── ParseObjectPutRequest.as │ │ ├── facebook │ │ │ ├── enums │ │ │ │ ├── FacebookRelationshipStatus.as │ │ │ │ ├── FacebookGender.as │ │ │ │ ├── FacebookPostType.as │ │ │ │ ├── FacebookPageCategory.as │ │ │ │ ├── FacebookPrivacyType.as │ │ │ │ ├── FacebookAlbumType.as │ │ │ │ └── FacebookPermissions.as │ │ │ ├── data │ │ │ │ ├── FacebookFeedPostAction.as │ │ │ │ ├── FacebookLocation.as │ │ │ │ ├── FacebookComment.as │ │ │ │ ├── FacebookPage.as │ │ │ │ ├── FacebookTag.as │ │ │ │ ├── FacebookAuthor.as │ │ │ │ └── FacebookAlbum.as │ │ │ ├── FacebookDataUtils.as │ │ │ ├── events │ │ │ │ ├── FacebookServiceEvent.as │ │ │ │ └── FacebookAuthEvent.as │ │ │ └── services │ │ │ │ ├── BasicFacebookRequest.as │ │ │ │ ├── FacebookFeedItemRequest.as │ │ │ │ ├── FacebookUserRequest.as │ │ │ │ ├── FacebookUsersRequest.as │ │ │ │ ├── FacebookFeedRequest.as │ │ │ │ ├── FacebookPostsRequest.as │ │ │ │ ├── FacebookAlbumsRequest.as │ │ │ │ └── FacebookAlbumPhotosRequest.as │ │ ├── bitly │ │ │ ├── BitLyConstants.as │ │ │ ├── data │ │ │ │ └── BitLyShortURL.as │ │ │ └── events │ │ │ │ └── BitLyEvent.as │ │ └── youtube │ │ │ ├── YouTubeDataUtils.as │ │ │ ├── data │ │ │ ├── YouTubeCategory.as │ │ │ └── YouTubeThumbnail.as │ │ │ ├── YouTubeConstants.as │ │ │ ├── events │ │ │ └── YouTubeServiceEvent.as │ │ │ └── services │ │ │ ├── YouTubeVideoInfoRequest.as │ │ │ └── YouTubeUserUploadsRequest.as │ ├── loaders │ │ ├── VideoLoaderEvent.as │ │ └── VideoLoaderCuePointEvent.as │ └── assets │ │ └── AssetType.as │ ├── controllers │ └── focus │ │ └── IFocusable.as │ ├── math │ └── equations │ │ └── operations │ │ ├── functions │ │ ├── RoundFunctionOperation.as │ │ ├── CosFunctionOperation.as │ │ ├── FunctionOperation.as │ │ └── SinFunctionOperation.as │ │ ├── modifiers │ │ ├── ModifierOperation.as │ │ ├── NegativeModifierOperation.as │ │ └── PositiveModifierOperation.as │ │ ├── operators │ │ ├── ParenthesisCloseOperation.as │ │ ├── ParenthesisOpenOperation.as │ │ ├── AddOperation.as │ │ ├── ModOperation.as │ │ ├── DivideOperation.as │ │ ├── PowerOperation.as │ │ ├── SubtractOperation.as │ │ └── MultiplyOperation.as │ │ └── BasicOperation.as │ ├── localization │ └── StringListEvent.as │ ├── data │ ├── starling │ │ └── TextureBank.as │ ├── types │ │ ├── DateTime.as │ │ ├── RandomBooleanSequence.as │ │ ├── RandomNumberSequence.as │ │ ├── NoisePlane.as │ │ └── NoiseSequence.as │ ├── GarbageCan.as │ └── ObjectPool.as │ ├── geom │ ├── QuadraticBezierCurve.as │ ├── CubicBezierCurve.as │ └── AbstractCurve.as │ ├── navigation │ ├── SpriteNavigatorEvent.as │ ├── NavigableSpriteEvent.as │ └── ResizableNavigableSprite.as │ └── signals │ └── SimpleSignal.as └── README.md /com/zehfernando/utils/console/logOn.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function logOn():void { 6 | Console.logOn(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/logOff.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function logOff():void { 6 | Console.logOff(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/log.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function log(... __args:Array):void { 6 | Console.log(__args); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/debug.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function debug(... __args:Array):void { 6 | Console.debug(__args); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/error.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function error(... __args:Array):void { 6 | Console.error(__args); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/info.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function info(... __args:Array):void { 6 | Console.info(__args); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/warn.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function warn(... __args:Array):void { 6 | Console.warn(__args); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/display/interfaces/IDisposable.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.interfaces { 2 | /** 3 | * @author zeh 4 | */ 5 | public interface IDisposable { 6 | 7 | function dispose(): void; 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /com/zehfernando/utils/console/logStackTrace.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.console { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public function logStackTrace():void { 6 | Console.logStackTrace(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/parse/ParseConstants.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.parse { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class ParseConstants { 6 | public static const DOMAIN:String = "https://api.parse.com"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookRelationshipStatus.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookRelationshipStatus { 7 | 8 | public static const IN_A_RELATIONSHIP:String = "In a Relationship"; 9 | 10 | // ...Missing a bunch more 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookGender.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookGender { 7 | 8 | public static const MALE:String = "male"; 9 | public static const FEMALE:String = "female"; 10 | public static const UNKNOWN:String = ""; 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /com/zehfernando/utils/getTimerUInt.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | import flash.utils.getTimer; 3 | /** 4 | * @author zeh at zehfernando.com 5 | */ 6 | 7 | // A safe getTimer() - runs for ~1192 hours instead of ~596 8 | public function getTimerUInt():uint { 9 | var v:int = getTimer(); 10 | return v < 0 ? int.MAX_VALUE + 1 + v - int.MIN_VALUE : v; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookPostType.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookPostType { 7 | 8 | public static const STATUS:String = "status"; 9 | public static const LINK:String = "link"; 10 | public static const VIDEO:String = "video"; 11 | public static const PHOTO:String = "photo"; 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookPageCategory.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookPageCategory { 7 | 8 | public static const PRODUCTS_OTHER:String = "Products_other"; 9 | public static const TECHNOLOGY:String = "Technology"; 10 | 11 | // Locations: 12 | public static const INTEREST:String = "Interest"; 13 | public static const CITY:String = "City"; 14 | 15 | // ...Missing a bunch more 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/bitly/BitLyConstants.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.bitly { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class BitLyConstants { 7 | 8 | public static const STATUS_CODE_SUCCESS:int = 200; 9 | public static const STATUS_CODE_ERROR_RATE_LIMITING:int = 403; 10 | public static const STATUS_CODE_ERROR_REQUEST:int = 500; 11 | public static const STATUS_CODE_ERROR_UNKNOWN:int = 503; 12 | 13 | public static const DOMAIN:String = "http://api.bit.ly"; 14 | public static const SERVICE_SHORTEN:String = "/v3/shorten"; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /com/zehfernando/display/components/text/TextSpriteAlign.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.components.text { 2 | 3 | /** 4 | * @author Zeh 5 | */ 6 | public class TextSpriteAlign { 7 | 8 | // Constants 9 | public static const TOP:String = "top"; 10 | public static const MIDDLE:String = "middle"; 11 | public static const BOTTOM:String = "bottom"; 12 | public static const BASELINE:String = "baseline"; 13 | 14 | public static const LEFT:String = "left"; 15 | public static const CENTER:String = "center"; 16 | public static const RIGHT:String = "right"; 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookPrivacyType.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public class FacebookPrivacyType { 6 | 7 | // https://developers.facebook.com/docs/reference/api/post/ 8 | 9 | public static const EVERYONE:String = "everyone"; 10 | public static const ALL_FRIENDS:String = "ALL_FRIENDS"; 11 | public static const NETWORKS_FRIENDS:String = "NETWORKS_FRIENDS"; 12 | public static const FRIENDS_OF_FRIENDS:String = "FRIENDS_OF_FRIENDS"; 13 | public static const CUSTOM:String = "CUSTOM"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/YouTubeDataUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class YouTubeDataUtils { 7 | 8 | public static function fromStringToSeconds(__time:String):Number { 9 | // Converts from "00:00:13.750" to a number of seconds 10 | 11 | var hours:int = parseInt(__time.substr(0, 2)); 12 | var minutes:int = parseInt(__time.substr(3, 2)); 13 | var seconds:int = parseInt(__time.substr(6, 2)); 14 | var milliSeconds:int = parseInt(__time.substr(9, 3)); 15 | return hours * 60 * 60 + minutes * 60 + seconds + milliSeconds/1000; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/bitly/data/BitLyShortURL.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.bitly.data { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class BitLyShortURL { 7 | 8 | // Properties 9 | public var url:String; 10 | public var hash:String; 11 | public var globalHash:String; 12 | public var longURL:String; 13 | public var newHash:Boolean; 14 | 15 | // ================================================================================================================ 16 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 17 | 18 | public function BitLyShortURL() { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/data/YouTubeCategory.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube.data { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class YouTubeCategory { 7 | 8 | // Properties 9 | public var term:String; 10 | public var label:String; 11 | 12 | // ================================================================================================================ 13 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 14 | 15 | public function YouTubeCategory(__term:String = "", __label:String = "") { 16 | term = __term; 17 | label = __label; 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookAlbumType.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public class FacebookAlbumType { 6 | 7 | public static const PROFILE:String = "profile"; // "The album containing profile pictures" 8 | public static const MOBILE:String = "mobile"; // "The album containing mobile upload photos" 9 | public static const WALL:String = "wall"; // "The album containing photos posted to a user's Wall" 10 | public static const NORMAL:String = "normal"; // "The album containing photos posted to a user's Wall" 11 | public static const ALBUM:String = "album"; 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookFeedPostAction.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | /** 3 | * @author zeh 4 | */ 5 | public class FacebookFeedPostAction { 6 | 7 | // Properties 8 | public var name:String; 9 | public var link:String; 10 | 11 | // ================================================================================================================ 12 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 13 | 14 | public function FacebookFeedPostAction(__name:String = "", __link:String = "") { 15 | super(); 16 | 17 | name = __name; 18 | link = __link; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /com/zehfernando/controllers/focus/IFocusable.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.controllers.focus { 2 | import flash.geom.Rectangle; 3 | /** 4 | * @author zeh fernando 5 | */ 6 | public interface IFocusable { 7 | function setFocused(__isFocused:Boolean, __immediate:Boolean = false):void; // So it can tell the item whether it's focused or not 8 | function getVisualBounds():Rectangle; // To calculate position for moving with the arrows 9 | function wasClickSimulated():Boolean; // Whether the click came from simulate() or not 10 | function simulateEnterDown():void; 11 | function simulateEnterUp():void; 12 | function simulateEnterCancel():void; 13 | function canReceiveFocus():Boolean; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /com/zehfernando/utils/ArrayUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | /** 3 | * @author zeh 4 | */ 5 | public class ArrayUtils { 6 | 7 | public static function shuffle(__array:Array): Array { 8 | // startIndex:int = 0, endIndex:int = 0):Array{ 9 | // if(endIndex == 0) endIndex = this.length-1; 10 | var newArray:Array = []; 11 | while (__array.length > 0) { 12 | newArray.splice(Math.floor(Math.random() * (newArray.length+1)), 0, __array.pop()); 13 | } 14 | 15 | return newArray; 16 | } 17 | 18 | public static function stringArrayToNumberArray(__array:Array):Array { 19 | var l:Array = []; 20 | if (Boolean(__array)) { 21 | for (var i:int = 0; i < __array.length; i++) l.push(parseFloat(__array[i])); 22 | } 23 | return l; 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/data/YouTubeThumbnail.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube.data { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class YouTubeThumbnail { 7 | 8 | // Properties 9 | public var url:String; 10 | public var height:int; 11 | public var width:int; 12 | public var time:Number; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function YouTubeThumbnail(__url:String = "", __height:int = 0, __width:int = 0, __time:Number = 0) { 18 | url = __url; 19 | height = __height; 20 | width = __width; 21 | time = __time; 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/YouTubeConstants.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class YouTubeConstants { 7 | 8 | public static const SCHEMA_KEYWORD:String = "http://gdata.youtube.com/schemas/2007/keywords.cat"; 9 | public static const SCHEMA_CATEGORY:String = "http://gdata.youtube.com/schemas/2007/categories.cat"; 10 | 11 | public static const NAMESPACE_GD:String = "gd"; 12 | public static const NAMESPACE_YT:String = "yt"; 13 | public static const NAMESPACE_MEDIA:String = "media"; 14 | 15 | public static const DOMAIN:String = "http://gdata.youtube.com"; 16 | public static const SERVICE_VIDEO_INFO:String = "/feeds/api/videos/[[video_id]]"; 17 | public static const SERVICE_USER_UPLOADS:String = "/feeds/api/users/[[user_id]]/uploads"; 18 | 19 | public static const PARAMETER_VIDEO_ID:String = "[[video_id]]"; 20 | public static const PARAMETER_USER_ID:String = "[[user_id]]"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/FacebookDataUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook { 2 | 3 | import com.zehfernando.utils.DateUtils; 4 | 5 | /** 6 | * @author zeh 7 | */ 8 | public class FacebookDataUtils { 9 | 10 | public static function getResultStringAsDate(__text:String):Date { 11 | // Converts '2010-08-13T21:12:40+0000' to a real date 12 | return DateUtils.xsdDateTimeToDate(__text); 13 | } 14 | 15 | public static function getImageURLSafeReplacement(__url:String):String { 16 | // Given an static image URL, replaces domains that don't work (https domains) with the http counterpart 17 | 18 | var i:int; 19 | var newDomain:String; 20 | var reps:Array = FacebookConstants.IMAGE_DOMAIN_REPLACEMENTS; 21 | 22 | for (i = 0; i < reps.length; i++) { 23 | newDomain = reps[i][1+Math.floor(Math.random() * ((reps[i] as Array).length-1))]; 24 | __url = __url.split(reps[i][0]).join(newDomain); 25 | } 26 | 27 | return __url; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /com/zehfernando/display/decorators/AbstractDecorator.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.decorators { 2 | import flash.display.DisplayObject; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class AbstractDecorator { 8 | 9 | // Properties 10 | protected var _target:DisplayObject; 11 | 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function AbstractDecorator(__target:DisplayObject) { 17 | _target = __target; 18 | apply(); 19 | } 20 | 21 | // ================================================================================================================ 22 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 23 | 24 | protected function apply():void { 25 | throw new Error("This must be overridden."); 26 | } 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/functions/RoundFunctionOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.functions { 2 | 3 | /** 4 | * @author zeh at zehfernando.com 5 | */ 6 | public class RoundFunctionOperation extends FunctionOperation { 7 | 8 | // ================================================================================================================ 9 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 10 | 11 | public function RoundFunctionOperation() { 12 | super(); 13 | } 14 | 15 | // ================================================================================================================ 16 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 17 | 18 | override public function operate(...__params):Number { 19 | return Math.round(__params[0]); 20 | } 21 | 22 | override public function toString():String { 23 | return "(round)"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/functions/CosFunctionOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.functions { 2 | 3 | /** 4 | * @author zeh at zehfernando.com 5 | */ 6 | public class CosFunctionOperation extends FunctionOperation { 7 | 8 | // ================================================================================================================ 9 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 10 | 11 | public function CosFunctionOperation() { 12 | super(); 13 | } 14 | 15 | // ================================================================================================================ 16 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 17 | 18 | override public function operate(...__params):Number { 19 | return Math.cos((__params[0] / 180) * Math.PI); 20 | } 21 | 22 | override public function toString():String { 23 | return "(cos)"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/modifiers/ModifierOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.modifiers { 2 | 3 | import com.zehfernando.math.equations.operations.BasicOperation; 4 | 5 | /** 6 | * @author zeh at zehfernando.com 7 | */ 8 | public class ModifierOperation extends BasicOperation { 9 | 10 | // ================================================================================================================ 11 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 12 | 13 | public function ModifierOperation() { 14 | super(); 15 | 16 | _precedence = 1000; 17 | _numParameters = 1; 18 | } 19 | 20 | // ================================================================================================================ 21 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 22 | 23 | override public function toString():String { 24 | return "[operation]"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/functions/FunctionOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.functions { 2 | 3 | import com.zehfernando.math.equations.operations.BasicOperation; 4 | 5 | /** 6 | * @author zeh at zehfernando.com 7 | */ 8 | public class FunctionOperation extends BasicOperation { 9 | 10 | // ================================================================================================================ 11 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 12 | 13 | public function FunctionOperation() { 14 | super(); 15 | 16 | _precedence = -1000; 17 | _numParameters = 1; 18 | } 19 | 20 | // ================================================================================================================ 21 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 22 | 23 | override public function toString():String { 24 | return "(function)"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/ParenthesisCloseOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class ParenthesisCloseOperation extends BasicOperation { 8 | 9 | // Special kind 10 | 11 | // ================================================================================================================ 12 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 13 | 14 | public function ParenthesisCloseOperation() { 15 | super(); 16 | 17 | _precedence = -1; 18 | } 19 | 20 | // ================================================================================================================ 21 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 22 | 23 | override public function toString():String { 24 | return ")"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/ParenthesisOpenOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class ParenthesisOpenOperation extends BasicOperation { 8 | 9 | // Special kind 10 | 11 | // ================================================================================================================ 12 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 13 | 14 | public function ParenthesisOpenOperation() { 15 | super(); 16 | 17 | _precedence = -1; 18 | } 19 | 20 | // ================================================================================================================ 21 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 22 | 23 | override public function toString():String { 24 | return "("; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/utils/NumberUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class NumberUtils { 7 | 8 | public static function formatNumber(__value:Number, __thousandsSeparator:String = ",", __decimalSeparator:String = ".", __decimalPlaces:Number = NaN):String { 9 | 10 | var nInt:Number = Math.floor(__value); 11 | var nDec:Number = __value - nInt; 12 | 13 | var sInt:String = nInt.toString(10); 14 | var sDec:String; 15 | 16 | if (!isNaN(__decimalPlaces)) { 17 | sDec = (Math.round(nDec * Math.pow(10, __decimalPlaces)) / Math.pow(10, __decimalPlaces)).toString(10).substr(2); 18 | } else { 19 | sDec = nDec == 0 ? "" : nDec.toString(10).substr(2); 20 | } 21 | 22 | var fInt:String = ""; 23 | var i:Number; 24 | for (i = 0; i < sInt.length; i++) { 25 | fInt += sInt.substr(i, 1); 26 | if ((sInt.length - i - 1) % 3 == 0 && i != sInt.length - 1) fInt += __thousandsSeparator; 27 | } 28 | 29 | return fInt + (sDec.length > 0 ? __decimalSeparator + sDec : ""); 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /com/zehfernando/localization/StringListEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.localization { 2 | 3 | import flash.events.Event; 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class StringListEvent extends Event { 8 | 9 | // Constants 10 | public static const CHANGED_LANGUAGE:String = "onChangedLanguage"; 11 | 12 | // ================================================================================================================ 13 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 14 | 15 | public function StringListEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) { 16 | super(type, bubbles, cancelable); 17 | } 18 | 19 | // ================================================================================================================ 20 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 21 | 22 | override public function clone(): Event { 23 | return new StringListEvent(type, bubbles, cancelable); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/AddOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class AddOperation extends BasicOperation { 8 | 9 | // ================================================================================================================ 10 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 11 | 12 | public function AddOperation() { 13 | super(); 14 | 15 | _precedence = 2; 16 | } 17 | 18 | // ================================================================================================================ 19 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 20 | 21 | override public function operate(...__params):Number { 22 | return __params[0] + __params[1]; 23 | } 24 | 25 | override public function toString():String { 26 | return "+"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/ModOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class ModOperation extends BasicOperation { 8 | 9 | // ================================================================================================================ 10 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 11 | 12 | public function ModOperation() { 13 | super(); 14 | 15 | _precedence = 3; 16 | } 17 | 18 | // ================================================================================================================ 19 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 20 | 21 | override public function operate(...__params):Number { 22 | return __params[0] % __params[1]; 23 | } 24 | 25 | override public function toString():String { 26 | return "%"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/DivideOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class DivideOperation extends BasicOperation { 8 | 9 | // ================================================================================================================ 10 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 11 | 12 | public function DivideOperation() { 13 | super(); 14 | 15 | _precedence = 3; 16 | } 17 | 18 | // ================================================================================================================ 19 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 20 | 21 | override public function operate(...__params):Number { 22 | return __params[0] / __params[1]; 23 | } 24 | 25 | override public function toString():String { 26 | return "/"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/modifiers/NegativeModifierOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.modifiers { 2 | 3 | import com.zehfernando.math.equations.operations.modifiers.ModifierOperation; 4 | 5 | /** 6 | * @author zeh at zehfernando.com 7 | */ 8 | public class NegativeModifierOperation extends ModifierOperation { 9 | 10 | // ================================================================================================================ 11 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 12 | 13 | public function NegativeModifierOperation() { 14 | super(); 15 | } 16 | 17 | // ================================================================================================================ 18 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 19 | 20 | override public function operate(...__params):Number { 21 | return -__params[0]; 22 | } 23 | override public function toString():String { 24 | return "[-]"; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/PowerOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class PowerOperation extends BasicOperation { 8 | 9 | // ================================================================================================================ 10 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 11 | 12 | public function PowerOperation() { 13 | super(); 14 | 15 | _precedence = 4; 16 | } 17 | 18 | // ================================================================================================================ 19 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 20 | 21 | override public function operate(...__params):Number { 22 | return Math.pow(__params[0], __params[1]); 23 | } 24 | 25 | override public function toString():String { 26 | return "^"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/SubtractOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class SubtractOperation extends BasicOperation { 8 | 9 | // ================================================================================================================ 10 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 11 | 12 | public function SubtractOperation() { 13 | super(); 14 | 15 | _precedence = 2; 16 | } 17 | 18 | // ================================================================================================================ 19 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 20 | 21 | override public function operate(...__params):Number { 22 | return __params[0] - __params[1]; 23 | } 24 | 25 | override public function toString():String { 26 | return "-"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/operators/MultiplyOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.operators { 2 | import com.zehfernando.math.equations.operations.BasicOperation; 3 | 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class MultiplyOperation extends BasicOperation { 8 | 9 | // ================================================================================================================ 10 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 11 | 12 | public function MultiplyOperation() { 13 | super(); 14 | 15 | _precedence = 3; 16 | } 17 | 18 | // ================================================================================================================ 19 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 20 | 21 | override public function operate(...__params):Number { 22 | return __params[0] * __params[1]; 23 | } 24 | 25 | override public function toString():String { 26 | return "*"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/functions/SinFunctionOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.functions { 2 | 3 | import com.zehfernando.math.equations.operations.functions.FunctionOperation; 4 | 5 | /** 6 | * @author zeh at zehfernando.com 7 | */ 8 | public class SinFunctionOperation extends FunctionOperation { 9 | 10 | // ================================================================================================================ 11 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 12 | 13 | public function SinFunctionOperation() { 14 | super(); 15 | } 16 | 17 | // ================================================================================================================ 18 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 19 | 20 | override public function operate(...__params):Number { 21 | return Math.sin((__params[0] / 180) * Math.PI); 22 | } 23 | 24 | override public function toString():String { 25 | return "(sin)"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/parse/events/ParseServiceEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.parse.events { 2 | import flash.events.Event; 3 | /** 4 | * @author zeh fernando 5 | */ 6 | public class ParseServiceEvent extends Event { 7 | 8 | // Constants 9 | public static const COMPLETE:String = "onComplete"; 10 | public static const ERROR:String = "onError"; 11 | 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function ParseServiceEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 17 | super(__type, __bubbles, __cancelable); 18 | } 19 | 20 | // ================================================================================================================ 21 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 22 | 23 | override public function clone(): Event { 24 | return new ParseServiceEvent(type, bubbles, cancelable); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/parse/services/ParseObjectPostRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.parse.services { 2 | import com.zehfernando.net.apis.parse.ParseConstants; 3 | 4 | import flash.net.URLRequestMethod; 5 | 6 | /** 7 | * @author zeh fernando 8 | */ 9 | public class ParseObjectPostRequest extends BasicParseRequest { 10 | 11 | // ================================================================================================================ 12 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 13 | 14 | public function ParseObjectPostRequest(__className:String) { 15 | super(); 16 | 17 | requestURL = ParseConstants.DOMAIN + "/1/classes/" + __className; 18 | requestMethod = URLRequestMethod.POST; 19 | } 20 | 21 | // ================================================================================================================ 22 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 23 | 24 | override protected function getData():Object { 25 | return '{"title_post": "Oh hai there"}'; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/data/starling/TextureBank.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data.starling { 2 | import starling.textures.Texture; 3 | /** 4 | * @author zeh at zehfernando.com 5 | */ 6 | public class TextureBank { 7 | 8 | // Properties 9 | private static var textures:Object = {}; 10 | private static var length:int = 0; 11 | 12 | // ================================================================================================================ 13 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 14 | 15 | public static function get(__key:String):Texture { 16 | return has(__key) ? textures[__key] : null; 17 | } 18 | 19 | public static function put(__key:String, __texture:Texture):void { 20 | textures[__key] = __texture; 21 | length++; 22 | } 23 | 24 | public static function remove(__key:String):void { 25 | delete textures[__key]; 26 | length--; 27 | } 28 | 29 | public static function has(__key:String):Boolean{ 30 | return textures.hasOwnProperty(__key); 31 | } 32 | 33 | public static function clear():void { 34 | length = 0; 35 | textures = {}; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/modifiers/PositiveModifierOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations.modifiers { 2 | 3 | import com.zehfernando.math.equations.operations.modifiers.ModifierOperation; 4 | 5 | /** 6 | * @author zeh at zehfernando.com 7 | */ 8 | public class PositiveModifierOperation extends ModifierOperation { 9 | 10 | // Doesn't actually do anything 11 | 12 | // ================================================================================================================ 13 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 14 | 15 | public function PositiveModifierOperation() { 16 | super(); 17 | } 18 | 19 | // ================================================================================================================ 20 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 21 | 22 | override public function operate(...__params):Number { 23 | return -__params[0]; 24 | } 25 | override public function toString():String { 26 | return "[+]"; 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/events/YouTubeServiceEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube.events { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class YouTubeServiceEvent extends Event { 8 | 9 | // Constants 10 | public static const COMPLETE:String = "onComplete"; 11 | public static const ERROR:String = "onError"; 12 | 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function YouTubeServiceEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 18 | super(__type, __bubbles, __cancelable); 19 | } 20 | 21 | // ================================================================================================================ 22 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 23 | 24 | override public function clone(): Event { 25 | return new YouTubeServiceEvent(type, bubbles, cancelable); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/events/FacebookServiceEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.events { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class FacebookServiceEvent extends Event { 8 | 9 | // Constants 10 | public static const COMPLETE:String = "onComplete"; 11 | public static const ERROR:String = "onError"; 12 | 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function FacebookServiceEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 18 | super(__type, __bubbles, __cancelable); 19 | } 20 | 21 | // ================================================================================================================ 22 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 23 | 24 | override public function clone(): Event { 25 | return new FacebookServiceEvent(type, bubbles, cancelable); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/parse/services/ParseObjectPutRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.parse.services { 2 | import com.zehfernando.net.apis.parse.ParseConstants; 3 | 4 | import flash.net.URLRequestMethod; 5 | 6 | /** 7 | * @author zeh fernando 8 | */ 9 | public class ParseObjectPutRequest extends BasicParseRequest { 10 | 11 | // ================================================================================================================ 12 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 13 | 14 | public function ParseObjectPutRequest(__className:String, __objectId:String) { 15 | super(); 16 | 17 | requestURL = ParseConstants.DOMAIN + "/1/classes/" + __className + "/" + __objectId; 18 | requestMethod = URLRequestMethod.PUT; 19 | } 20 | 21 | // ================================================================================================================ 22 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 23 | 24 | override protected function getData():Object { 25 | return '{"title_put": "Hello World"}'; 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/zehfernando/display/templates/application/events/ApplicationFrame2Event.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.templates.application.events { 2 | 3 | import flash.events.Event; 4 | 5 | /** 6 | * @author zeh at zehfernando.com 7 | */ 8 | public class ApplicationFrame2Event extends Event { 9 | 10 | // Constants 11 | public static const INIT_PROGRESS:String = "onInitProgress"; 12 | public static const INIT_COMPLETE:String = "onInitComplete"; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function ApplicationFrame2Event(type:String, bubbles:Boolean = false, cancelable:Boolean = false) { 18 | super(type, bubbles, cancelable); 19 | } 20 | 21 | // ================================================================================================================ 22 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 23 | 24 | override public function clone(): Event { 25 | return new ApplicationFrame2Event(type, bubbles, cancelable); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /com/zehfernando/data/types/DateTime.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data.types { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public class DateTime { 6 | 7 | // Properties 8 | protected var _date:Date; 9 | 10 | // ================================================================================================================ 11 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 12 | 13 | public function DateTime() { 14 | } 15 | 16 | // ================================================================================================================ 17 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 18 | 19 | public static function fromString(): DateTime { 20 | var date:DateTime = new DateTime(); 21 | return date; 22 | } 23 | 24 | // ================================================================================================================ 25 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 26 | 27 | public function toDate(): Date { 28 | var date:Date = new Date(); 29 | return date; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /com/zehfernando/display/components/text/EditableTextSpriteEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.components.text { 2 | 3 | import flash.events.Event; 4 | /** 5 | * @author zeh 6 | */ 7 | public class EditableTextSpriteEvent extends Event { 8 | 9 | // Constants 10 | public static const GOT_FOCUS:String = "onGotFocus"; 11 | public static const LOST_FOCUS:String = "onLostFocus"; 12 | public static const CHANGED:String = "onChanged"; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function EditableTextSpriteEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 18 | super(__type, __bubbles, __cancelable); 19 | } 20 | 21 | // ================================================================================================================ 22 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 23 | 24 | override public function clone():Event { 25 | return new EditableTextSpriteEvent(type, bubbles, cancelable); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/display/templates/videoplayer/events/VideoPanelSeekEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.templates.videoplayer.events { 2 | 3 | import flash.events.Event; 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class VideoPanelSeekEvent extends Event { 8 | 9 | // Constants 10 | public static const SEEK:String = "onSeek"; 11 | 12 | // Properties 13 | public var time:Number; 14 | 15 | // ================================================================================================================ 16 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 17 | 18 | public function VideoPanelSeekEvent(__type:String, __time:Number, __bubbles:Boolean = false, __cancelable:Boolean = false) { 19 | super(__type, __bubbles, __cancelable); 20 | 21 | time = __time; 22 | } 23 | 24 | // ================================================================================================================ 25 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 26 | 27 | override public function clone(): Event { 28 | return new VideoPanelSeekEvent(type, time, bubbles, cancelable); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /com/zehfernando/geom/QuadraticBezierCurve.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.geom { 2 | import flash.geom.Point; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class QuadraticBezierCurve extends AbstractCurve { 8 | 9 | // Properties 10 | public var cp:Point; 11 | 12 | // Temp 13 | public var nt:Number; 14 | 15 | // ================================================================================================================ 16 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 17 | 18 | public function QuadraticBezierCurve(__p1:Point, __control:Point, __p2:Point) { 19 | super(__p1, __p2); 20 | cp = __control; 21 | } 22 | 23 | 24 | // ================================================================================================================ 25 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 26 | 27 | override public function getPointOnCurve(__t:Number):Point { 28 | // http://en.wikipedia.org/wiki/B%C3%A9zier_curve 29 | nt = 2 * (1-__t); 30 | return new Point( 31 | p1.x + __t * (nt * (cp.x - p1.x) + __t * (p2.x - p1.x)), 32 | p1.y + __t * (nt * (cp.y - p1.y) + __t * (p2.y - p1.y)) 33 | ); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /com/zehfernando/display/templates/videoplayer/events/VideoPanelVolumeEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.templates.videoplayer.events { 2 | 3 | import flash.events.Event; 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class VideoPanelVolumeEvent extends Event { 8 | 9 | // Constants 10 | public static const VOLUME_CHANGE:String = "onVolumeChange"; 11 | 12 | // Properties 13 | public var volume:Number; 14 | 15 | // ================================================================================================================ 16 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 17 | 18 | public function VideoPanelVolumeEvent(__type:String, __volume:Number, __bubbles:Boolean = false, __cancelable:Boolean = false) { 19 | super(__type, __bubbles, __cancelable); 20 | 21 | volume = __volume; 22 | } 23 | 24 | // ================================================================================================================ 25 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 26 | 27 | override public function clone(): Event { 28 | return new VideoPanelVolumeEvent(type, volume, bubbles, cancelable); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /com/zehfernando/data/types/RandomBooleanSequence.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data.types { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class RandomBooleanSequence { 6 | // A sequence of booleans numbers 7 | 8 | // Properties 9 | private var booleans:Vector.; 10 | private var index:int; 11 | private var oldIndex:int; 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function RandomBooleanSequence(__items:int = 97) { 17 | index = 0; 18 | booleans = new Vector.(); 19 | booleans.length = __items; 20 | booleans.fixed = true; 21 | for (var i:int = 0; i < booleans.length; i++) { 22 | booleans[i] = Math.random() < 0.5; 23 | } 24 | } 25 | 26 | // ================================================================================================================ 27 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 28 | 29 | public function getNext():Boolean { 30 | oldIndex = index; 31 | index = (index + 1) % booleans.length; 32 | return booleans[oldIndex]; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /com/zehfernando/data/types/RandomNumberSequence.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data.types { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class RandomNumberSequence { 6 | // A sequence of random numbers 7 | 8 | // Properties 9 | private var numbers:Vector.; 10 | private var index:int; 11 | private var oldIndex:int; 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function RandomNumberSequence(__min:Number = 0, __max:Number = 1, __items:int = 97) { 17 | index = 0; 18 | numbers = new Vector.(); 19 | numbers.length = __items; 20 | numbers.fixed = true; 21 | for (var i:int = 0; i < numbers.length; i++) { 22 | numbers[i] = __min + Math.random() * (__max - __min); 23 | } 24 | } 25 | 26 | // ================================================================================================================ 27 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 28 | 29 | public function getNext():Number { 30 | oldIndex = index; 31 | index = (index + 1) % numbers.length; 32 | return numbers[oldIndex]; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/statgraph/TotalMemoryDataPoint.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug.statgraph { 2 | import flash.system.System; 3 | 4 | /** 5 | * @author zeh fernando 6 | */ 7 | public class TotalMemoryDataPoint extends AbstractDataPoint { 8 | 9 | /** 10 | * Memory used by the SWF 11 | */ 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function TotalMemoryDataPoint() { 17 | super(); 18 | } 19 | 20 | 21 | // ================================================================================================================ 22 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 23 | 24 | override protected function setDefaultProperties():void { 25 | super.setDefaultProperties(); 26 | 27 | chartMax = 1024 * 1024 * 40; 28 | valueLabelUnit = 1024 * 1024; 29 | valueLabelUnitDecimalPoints = 1; 30 | color = 0x0066ff; 31 | } 32 | 33 | override protected function getDataPointValue():Number { 34 | return System.totalMemory; 35 | } 36 | 37 | override protected function getDataPointLabel():String { 38 | return "MB"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /com/zehfernando/math/equations/operations/BasicOperation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.math.equations.operations { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public class BasicOperation { 6 | 7 | // Properties 8 | protected var _precedence:Number; 9 | protected var _numParameters:int; 10 | 11 | // ================================================================================================================ 12 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 13 | 14 | public function BasicOperation() { 15 | _precedence = 0; 16 | _numParameters = 2; 17 | } 18 | 19 | // ================================================================================================================ 20 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 21 | 22 | public function operate(...__params):Number { 23 | return __params[0]; 24 | } 25 | 26 | public function operateAsModifier(__param:Number):Number { 27 | return __param; 28 | } 29 | 30 | public function get precedence():Number { 31 | return _precedence; 32 | } 33 | 34 | public function get numParameters():int { 35 | return _numParameters; 36 | } 37 | 38 | public function toString():String { 39 | return ""; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/statgraph/PrivateMemoryDataPoint.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug.statgraph { 2 | import flash.system.System; 3 | 4 | /** 5 | * @author zeh fernando 6 | */ 7 | public class PrivateMemoryDataPoint extends AbstractDataPoint { 8 | 9 | /** 10 | * Memory used by the player 11 | */ 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function PrivateMemoryDataPoint() { 17 | super(); 18 | } 19 | 20 | 21 | // ================================================================================================================ 22 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 23 | 24 | override protected function setDefaultProperties():void { 25 | super.setDefaultProperties(); 26 | 27 | chartMax = 1024 * 1024 * 100; 28 | valueLabelUnit = 1024 * 1024; 29 | valueLabelUnitDecimalPoints = 1; 30 | color = 0x0033ff; 31 | } 32 | 33 | override protected function getDataPointValue():Number { 34 | return System.privateMemory; 35 | } 36 | 37 | override protected function getDataPointLabel():String { 38 | return "MB (PVT)"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/statgraph/FPSDataPoint.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug.statgraph { 2 | 3 | /** 4 | * @author zeh fernando 5 | */ 6 | public class FPSDataPoint extends AbstractDataPoint { 7 | 8 | /** 9 | * Memory used by the SWF 10 | */ 11 | 12 | // ================================================================================================================ 13 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 14 | 15 | public function FPSDataPoint() { 16 | super(); 17 | } 18 | 19 | 20 | // ================================================================================================================ 21 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 22 | 23 | override protected function setDefaultProperties():void { 24 | super.setDefaultProperties(); 25 | 26 | chartMax = 60; 27 | color = 0xff2200; 28 | minMaxFromAveraged = true; 29 | } 30 | 31 | override protected function getDataPointValue():Number { 32 | return 1; 33 | } 34 | 35 | override protected function getDataPointValueAveraged(__timeSpentMS:Number):Number { 36 | return samples / (__timeSpentMS / 1000); 37 | } 38 | 39 | override protected function getDataPointLabel():String { 40 | return "FPS"; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /com/zehfernando/navigation/SpriteNavigatorEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.navigation { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class SpriteNavigatorEvent extends Event { 8 | 9 | public static const CHANGED_LOCATION:String = "onChangedLocation"; // Location has changed, on ANY location hop 10 | public static const CHANGED_LOCATION_FINAL:String = "onChangedLocationFinal"; // Location has changed, and it's on the final location 11 | public static const LOCATION_WILL_CHANGE:String = "onLocationBeforeChange"; // Location will change 12 | 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function SpriteNavigatorEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 18 | super(__type, __bubbles, __cancelable); 19 | } 20 | 21 | // ================================================================================================================ 22 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 23 | 24 | override public function clone(): Event { 25 | return new SpriteNavigatorEvent(type, bubbles, cancelable); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com/zehfernando/display/templates/videoplayer/events/VideoPanelEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.templates.videoplayer.events { 2 | import flash.events.Event; 3 | /** 4 | * @author zeh 5 | */ 6 | public class VideoPanelEvent extends Event { 7 | 8 | // Constants 9 | public static const PAUSE:String = "onPause"; 10 | public static const PLAY:String = "onPlay"; 11 | public static const SCRUB_START:String = "onScrubStart"; 12 | public static const SCRUB_END:String = "onScrubEnd"; 13 | public static const SCREEN_FULL:String = "onScreenFull"; 14 | public static const SCREEN_NORMAL:String = "onScreenNormal"; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function VideoPanelEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 20 | super(__type, __bubbles, __cancelable); 21 | } 22 | 23 | // ================================================================================================================ 24 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 25 | 26 | override public function clone(): Event { 27 | return new VideoPanelEvent(type, bubbles, cancelable); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/events/FacebookAuthEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.events { 2 | import flash.events.Event; 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookAuthEvent extends Event { 7 | 8 | // Constants 9 | public static const LOG_IN_SUCCESS:String = "onLogInSuccess"; 10 | public static const LOG_IN_ERROR:String = "onLogInError"; 11 | 12 | public static const LOG_OUT_SUCCESS:String = "onLogOutSuccess"; 13 | 14 | public static const GOT_APP_ACCESS_TOKEN_SUCCESS:String = "onGotAppAccessTokenSuccess"; 15 | public static const GOT_APP_ACCESS_TOKEN_ERROR:String = "onGotAppAccessTokenError"; 16 | 17 | // ================================================================================================================ 18 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 19 | 20 | public function FacebookAuthEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 21 | super(__type, __bubbles, __cancelable); 22 | } 23 | 24 | // ================================================================================================================ 25 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 26 | 27 | override public function clone(): Event { 28 | return new FacebookAuthEvent(type, bubbles, cancelable); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /com/zehfernando/display/templates/videoplayer/events/VideoPlayerEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.templates.videoplayer.events { 2 | 3 | import flash.events.Event; 4 | /** 5 | * @author zeh at zehfernando.com 6 | */ 7 | public class VideoPlayerEvent extends Event { 8 | 9 | // Constants 10 | // public static const PAUSE:String = "onPause"; 11 | // public static const PLAY:String = "onPlay"; 12 | // public static const SCRUB_START:String = "onScrubStart"; 13 | // public static const SCRUB_END:String = "onScrubEnd"; 14 | public static const SCREEN_FULL:String = "onScreenFull"; 15 | public static const SCREEN_NORMAL:String = "onScreenNormal"; 16 | 17 | // ================================================================================================================ 18 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 19 | 20 | public function VideoPlayerEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 21 | super(__type, __bubbles, __cancelable); 22 | } 23 | 24 | // ================================================================================================================ 25 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 26 | 27 | override public function clone(): Event { 28 | return new VideoPlayerEvent(type, bubbles, cancelable); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/enums/FacebookPermissions.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.enums { 2 | /** 3 | * @author zeh 4 | */ 5 | public class FacebookPermissions { 6 | 7 | // Full list: http://developers.facebook.com/docs/authentication/permissions 8 | // Must be asked during login! http://developers.facebook.com/docs/authentication/ 9 | 10 | public static const READ_STREAM:String = "read_stream"; // Provides access to all the posts in the user's News Feed and enables your application to perform searches against the user's News Feed 11 | 12 | public static const USER_PHOTO_VIDEO_TAGS:String = "user_photo_video_tags"; // Provides access to the photos the user has been tagged in as the `photos` connection 13 | public static const FRIENDS_PHOTO_VIDEO_TAGS:String = "friends_photo_video_tags"; 14 | 15 | public static const USER_PHOTOS:String = "user_photos"; // Provides access to the photos the user has uploaded 16 | public static const FRIENDS_PHOTOS:String = "friends_photos"; 17 | 18 | public static const USER_LOCATION:String = "user_location"; // Provides access to the user's current location as the location property 19 | public static const FRIENDS_LOCATION:String = "friends_location"; 20 | 21 | public static const PUBLISH_STREAM:String = "publish_stream"; // Enables your application to post content, comments, and likes to a user's stream and to the streams of the user's friends. With this permission, you can publish content to a user's feed at any time, without requiring offline_access. However, please note that Facebook recommends a user-initiated sharing model. 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /com/zehfernando/geom/CubicBezierCurve.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.geom { 2 | import flash.geom.Point; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class CubicBezierCurve extends AbstractCurve { 8 | 9 | // Properties 10 | public var cp1:Point; 11 | public var cp2:Point; 12 | 13 | // Temp 14 | public var nt:Number; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function CubicBezierCurve(__p1:Point, __control1:Point, __control2:Point, __p2:Point) { 20 | super (__p1, __p2); 21 | cp1 = __control1; 22 | cp2 = __control2; 23 | } 24 | 25 | // ================================================================================================================ 26 | // INSTANCE functions --------------------------------------------------------------------------------------------- 27 | 28 | 29 | // ================================================================================================================ 30 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 31 | 32 | override public function getPointOnCurve(__t:Number):Point { 33 | // http://en.wikipedia.org/wiki/B%C3%A9zier_curve 34 | nt = 1-__t; 35 | return new Point( 36 | nt * nt * nt * p1.x + 3 * nt * nt * __t * cp1.x + 3 * nt * __t * __t * cp2.x + __t * __t * __t * p2.x, 37 | nt * nt * nt * p1.y + 3 * nt * nt * __t * cp1.y + 3 * nt * __t * __t * cp2.y + __t * __t * __t * p2.y 38 | ); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookLocation.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookLocation { 7 | 8 | // https://graph.facebook.com/112047398814697 9 | // https://graph.facebook.com/108424279189115 10 | 11 | // Properties 12 | public var id:String; 13 | public var name:String; 14 | public var link:String; 15 | public var category:String; 16 | public var isCommunityPage:Boolean; 17 | public var description:String; 18 | public var fanCount:int; 19 | 20 | // ================================================================================================================ 21 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 22 | 23 | public function FacebookLocation() { 24 | super(); 25 | } 26 | 27 | // ================================================================================================================ 28 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 29 | 30 | public static function fromJSONObject(o:Object): FacebookLocation { 31 | if (!Boolean(o)) return null; 32 | 33 | var location:FacebookLocation = new FacebookLocation(); 34 | 35 | location.id = o["id"]; 36 | location.name = o["name"]; 37 | location.link = o["link"]; 38 | location.category = o["category"]; 39 | location.isCommunityPage = Boolean(o["is_community_page"]); 40 | location.description = o["description"]; 41 | location.fanCount = o["fan_count"]; 42 | 43 | return location; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/statgraph/CustomDataPoint.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug.statgraph { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class CustomDataPoint extends AbstractDataPoint { 6 | 7 | /** 8 | * A data point for anything 9 | */ 10 | 11 | // Properties 12 | private var label:String; 13 | private var value:Number; 14 | 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function CustomDataPoint(__label:String, __color:int, __chartMax:Number) { 20 | super(); 21 | label = __label; 22 | color = __color; 23 | chartMax = __chartMax; 24 | } 25 | 26 | 27 | // ================================================================================================================ 28 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 29 | 30 | override protected function getDataPointValue():Number { 31 | return value; 32 | } 33 | 34 | override protected function getDataPointLabel():String { 35 | return label; 36 | } 37 | 38 | // ================================================================================================================ 39 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 40 | 41 | public function setValue(__value:Number):void { 42 | value = __value; 43 | } 44 | 45 | public function setChartMax(__value:Number):void { 46 | chartMax = __value; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /com/zehfernando/display/components/text/RichTextSpriteEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.components.text { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class RichTextSpriteEvent extends Event { 8 | 9 | // Constants 10 | public static const LINK:String = "onClickLink"; 11 | 12 | // Properties 13 | protected var _href:String; 14 | protected var _hrefTarget:String; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function RichTextSpriteEvent(__type:String, __href:String, __hrefTarget:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 20 | _href = __href; 21 | _hrefTarget = __hrefTarget; 22 | 23 | super(__type, __bubbles, __cancelable); 24 | } 25 | 26 | // ================================================================================================================ 27 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 28 | 29 | override public function clone():Event { 30 | return new RichTextSpriteEvent(type, _href, _hrefTarget, bubbles, cancelable); 31 | } 32 | 33 | // ================================================================================================================ 34 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 35 | 36 | public function get href():String { 37 | return _href; 38 | } 39 | 40 | public function get hrefTarget():String { 41 | return _hrefTarget; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /com/zehfernando/data/types/NoisePlane.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data.types { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class NoisePlane { 6 | 7 | // Actually, a pseudo-noise sequence that is always repeatable and tileable (on the phase 0-1) 8 | 9 | // Constants 10 | private static const TWO_PI:Number = Math.PI * 2; 11 | 12 | // Properties 13 | private var octaves:int; 14 | private var randoms:Vector.; 15 | private var powers:Vector.; 16 | 17 | // Temp vars to reduce garbage collection 18 | private var r:Number; 19 | private var v:Number; 20 | private var i:Number; 21 | 22 | // ================================================================================================================ 23 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 24 | 25 | public function NoisePlane(__octaves:int = 5) { 26 | octaves = __octaves; 27 | randoms = new Vector.(); 28 | while (randoms.length < octaves) randoms.push(new NoiseSequence(__octaves)); 29 | powers = new Vector.(); 30 | while (powers.length < octaves) powers.push(Math.pow(2, powers.length)); 31 | } 32 | 33 | // ================================================================================================================ 34 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 35 | 36 | public function getNumber(__phaseX:Number, __phaseY:Number):Number { 37 | // Phase is 0-1 38 | 39 | r = __phaseX * TWO_PI; 40 | 41 | v = 0; 42 | for (i = 0; i < octaves; i++) v += Math.sin(r * powers[i] + randoms[i].getNumber(__phaseY) * Math.PI); 43 | v /= octaves; 44 | 45 | return v; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /com/zehfernando/display/utils/getRealBounds.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.utils { 2 | import flash.display.BitmapData; 3 | import flash.display.DisplayObject; 4 | import flash.geom.Matrix; 5 | import flash.geom.Rectangle; 6 | 7 | /** 8 | * @author zeh 9 | */ 10 | public function getRealBounds(__target:DisplayObject, __targetCoordinateSpace:DisplayObject, __safeMargin:Number = 20): Rectangle { 11 | // This is like DisplayObject.getBounds(), but correct 12 | // Safe margin does not expand the size, but should be as big as necessary - some items (like bottom of some fonts) fall outside the getBounds margin 13 | 14 | var rect:Rectangle = __target.getBounds(__target); 15 | 16 | var rx:Number = rect.x; 17 | var ry:Number = rect.y; 18 | var rw:Number = rect.width * __target.scaleX; 19 | var rh:Number = rect.height * __target.scaleY; 20 | 21 | if (rw <= 0) rw = 1; 22 | if (rh <= 0) rh = 1; 23 | 24 | var bmp:BitmapData = new BitmapData(Math.ceil(rw + __safeMargin * 2 * __target.scaleX), Math.ceil(rh + __safeMargin * 2 * __target.scaleY), true, 0x00000000); 25 | 26 | var mtx:Matrix = new Matrix(); 27 | mtx.scale(__target.scaleX, __target.scaleY); 28 | mtx.translate(__safeMargin * __target.scaleX, __safeMargin * __target.scaleY); 29 | mtx.translate(-rx * __target.scaleX, -ry * __target.scaleY); 30 | bmp.draw(__target, mtx); 31 | 32 | // Remove contents 33 | var rr:Rectangle = bmp.getColorBoundsRect(0xff000000, 0x00000000, false); 34 | 35 | bmp.dispose(); 36 | bmp = null; 37 | 38 | var fRect:Rectangle = __target.getBounds(__targetCoordinateSpace); 39 | fRect.x += rr.x - __safeMargin * __target.scaleX; 40 | fRect.y += rr.y - __safeMargin * __target.scaleY; 41 | fRect.width = rr.width; 42 | fRect.height = rr.height; 43 | 44 | return fRect; 45 | } 46 | } -------------------------------------------------------------------------------- /com/zehfernando/display/progressbars/RectangleProgressBar.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.progressbars { 2 | import com.zehfernando.display.shapes.Box; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class RectangleProgressBar extends AbstractProgressBar { 8 | 9 | // Instances 10 | protected var foreground:Box; 11 | protected var background:Box; 12 | 13 | // ================================================================================================================ 14 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 15 | 16 | public function RectangleProgressBar(__foregroundColor:int = 0xffffff, __foregroundAlpha:Number = 1, __backgroundColor:int = 0xffffff, __backgroundAlpha:Number = 0.25) { 17 | super(); 18 | 19 | // Create all assets 20 | background = new Box(100, 100, __backgroundColor); 21 | background.alpha = __backgroundAlpha; 22 | background.visible = __backgroundAlpha > 0; 23 | addChild(background); 24 | 25 | foreground = new Box(100, 100, __foregroundColor); 26 | foreground.alpha = __foregroundAlpha; 27 | foreground.visible = __foregroundAlpha > 0; 28 | addChild(foreground); 29 | } 30 | 31 | // ================================================================================================================ 32 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 33 | 34 | override protected function redrawAmount():void { 35 | // Redraws graphics to represent the correct amount 36 | //trace ("====> " + _value.current, _value.target); 37 | foreground.width = 100 * _value.current; 38 | 39 | background.x = foreground.width; 40 | background.width = 100 - foreground.width; 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /com/zehfernando/display/shapes/PointMarker.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.shapes { 2 | import flash.display.Sprite; 3 | 4 | /** 5 | * @author Zeh 6 | */ 7 | public class PointMarker extends Sprite { 8 | 9 | // Properties 10 | protected var _color:Number; 11 | protected var _circleRadius:Number; 12 | protected var _lineRadius:Number; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function PointMarker(__color:Number = 0xff00ff) { 18 | _color = __color & 0xffffff; 19 | _circleRadius = 20; 20 | _lineRadius = 30; 21 | 22 | paint(); 23 | } 24 | 25 | 26 | // ================================================================================================================ 27 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 28 | 29 | protected function paint():void { 30 | graphics.clear(); 31 | graphics.lineStyle(1, _color); 32 | graphics.drawCircle(0, 0, _circleRadius); 33 | graphics.moveTo(0, -_lineRadius); 34 | graphics.lineTo(0, _lineRadius); 35 | graphics.moveTo(-_lineRadius, 0); 36 | graphics.lineTo(_lineRadius, 0); 37 | } 38 | 39 | 40 | // ================================================================================================================ 41 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 42 | 43 | public function get color():int { 44 | return _color; 45 | } 46 | public function set color(__value:int):void { 47 | if (_color != __value) { 48 | _color = __value; 49 | paint(); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/statgraph/MSDataPoint.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug.statgraph { 2 | import com.zehfernando.utils.getTimerUInt; 3 | /** 4 | * @author zeh fernando 5 | */ 6 | public class MSDataPoint extends AbstractDataPoint { 7 | 8 | /** 9 | * Time spent for code calculation 10 | */ 11 | 12 | // Properties 13 | private var timeFrameEntered:uint; 14 | 15 | // ================================================================================================================ 16 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 17 | 18 | public function MSDataPoint() { 19 | super(); 20 | } 21 | 22 | 23 | // ================================================================================================================ 24 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 25 | 26 | override protected function setDefaultProperties():void { 27 | super.setDefaultProperties(); 28 | 29 | chartMax = (1000 / 60) * 2; 30 | color = 0x44cc00; 31 | 32 | } 33 | 34 | override protected function getDataPointValue():Number { 35 | return getTimerUInt() - timeFrameEntered; 36 | } 37 | 38 | override protected function getDataPointLabel():String { 39 | return "MS/F"; 40 | } 41 | 42 | // ================================================================================================================ 43 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 44 | 45 | override public function updateValuesEnterFrame():void { 46 | timeFrameEntered = getTimerUInt(); 47 | } 48 | 49 | override public function updateValuesExitFrame():void { 50 | addDataPoint(); 51 | } 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /com/zehfernando/data/types/NoiseSequence.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data.types { 2 | import com.zehfernando.utils.RandomGenerator; 3 | /** 4 | * @author zeh fernando 5 | */ 6 | public class NoiseSequence { 7 | 8 | // Actually, a pseudo-noise sequence that is always repeatable and tileable (on the phase 0-1) 9 | 10 | // Constants 11 | private static const TWO_PI:Number = Math.PI * 2; 12 | 13 | // Properties 14 | private var octaves:int; 15 | private var randoms:Vector.; 16 | private var powers:Vector.; 17 | 18 | // Temp vars to reduce garbage collection 19 | private var r:Number; 20 | private var v:Number; 21 | private var i:Number; 22 | 23 | // ================================================================================================================ 24 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 25 | 26 | public function NoiseSequence(__octaves:int = 5, __randomSeed:int = -1) { 27 | octaves = __octaves; 28 | randoms = new Vector.(); 29 | var pos:int = 0; 30 | while (randoms.length < octaves) randoms.push(RandomGenerator.getFromSeed(__randomSeed < 0 ? -1 : __randomSeed + (pos++)) * TWO_PI); 31 | powers = new Vector.(); 32 | while (powers.length < octaves) powers.push(Math.pow(2, powers.length)); 33 | } 34 | 35 | // ================================================================================================================ 36 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 37 | 38 | public function getNumber(__phase:Number):Number { 39 | // Phase is 0-1 40 | 41 | r = __phase * TWO_PI; 42 | 43 | v = 0; 44 | for (i = 0; i < octaves; i++) v += Math.sin(r * powers[i] + randoms[i]); 45 | v /= octaves; 46 | 47 | return v; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookComment.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | import com.zehfernando.net.apis.facebook.FacebookDataUtils; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class FacebookComment { 8 | 9 | // https://graph.facebook.com/136208713078882_146368762058100/comments 10 | 11 | // Properties 12 | public var id:String; 13 | public var from:FacebookAuthor; 14 | public var message:String; 15 | public var created:Date; 16 | 17 | // ================================================================================================================ 18 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 19 | 20 | public function FacebookComment() { 21 | } 22 | 23 | // ================================================================================================================ 24 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 25 | 26 | public static function fromJSONObject(o:Object): FacebookComment { 27 | if (!Boolean(o)) return null; 28 | 29 | var comment:FacebookComment = new FacebookComment(); 30 | 31 | comment.id = o["id"]; 32 | comment.from = FacebookAuthor.fromJSONObject(o["from"]); 33 | comment.message = o["message"]; 34 | comment.created = FacebookDataUtils.getResultStringAsDate(o["created_time"]); 35 | 36 | return comment; 37 | } 38 | 39 | public static function fromJSONObjectArray(o:Array): Vector. { 40 | var comments:Vector. = new Vector.(); 41 | 42 | if (!Boolean(o)) return comments; 43 | 44 | for (var i:int = 0; i < o.length; i++) { 45 | comments.push(FacebookComment.fromJSONObject(o[i])); 46 | } 47 | 48 | return comments; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /com/zehfernando/display/progressbars/CircularProgressBar.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.progressbars { 2 | import com.zehfernando.display.shapes.CircleSlice; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class CircularProgressBar extends AbstractProgressBar { 8 | 9 | // Properties 10 | protected var angleOffset:Number; 11 | 12 | // Instances 13 | protected var baseCircle:CircleSlice; 14 | protected var loadingCircle:CircleSlice; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function CircularProgressBar(__innerRadius:Number = 5, __outerRadius:Number = 10, __color:int = 0xffffff, __backgroundAlpha:Number = 0.25, __foregroundAlpha:Number = 1, __angleOffset:Number = -90) { 20 | super(); 21 | 22 | angleOffset = __angleOffset; 23 | 24 | // Create all assets 25 | baseCircle = new CircleSlice(__outerRadius, __color, __innerRadius); 26 | baseCircle.alpha = __backgroundAlpha; 27 | baseCircle.visible = __backgroundAlpha > 0; 28 | addChild(baseCircle); 29 | 30 | loadingCircle = new CircleSlice(__outerRadius, __color, __innerRadius, angleOffset); 31 | loadingCircle.alpha = __foregroundAlpha; 32 | loadingCircle.visible = __foregroundAlpha > 0; 33 | addChild(loadingCircle); 34 | } 35 | 36 | // ================================================================================================================ 37 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 38 | 39 | override protected function redrawAmount():void { 40 | // Redraws graphics to represent the correct amount 41 | loadingCircle.endAngle = angleOffset + _value.current * 360; 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /com/zehfernando/net/loaders/VideoLoaderEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.loaders { 2 | import flash.events.Event; 3 | /** 4 | * @author zeh 5 | */ 6 | public class VideoLoaderEvent extends Event { 7 | 8 | // Constants 9 | public static const SEEK_NOTIFY:String = "onSeekNotify"; 10 | public static const STREAM_NOT_FOUND:String = "onStreamNotFound"; 11 | public static const BUFFER_EMPTY:String = "onBufferEmpty"; 12 | public static const BUFFER_FULL:String = "onBufferFull"; 13 | public static const BUFFER_FLUSH:String = "onBufferFlush"; 14 | public static const PLAY_START:String = "onPlayStart"; // First play 15 | public static const RESUME:String = "onResume"; // Any play 16 | public static const PAUSE:String = "onPause"; // Any pause 17 | public static const PLAY_STOP:String = "onPlayStop"; 18 | public static const PLAY_FINISH:String = "onPlayFinish"; 19 | public static const RECEIVED_XMP_DATA: String = "onReceivedXMPData"; 20 | public static const RECEIVED_METADATA: String = "onReceivedMetaData"; 21 | public static const TIME_CHANGE: String = "onTimeChange"; 22 | 23 | // ================================================================================================================ 24 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 25 | 26 | public function VideoLoaderEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false):void { 27 | super(__type, __bubbles, __cancelable); 28 | } 29 | 30 | // ================================================================================================================ 31 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 32 | 33 | override public function clone():Event { 34 | return new VideoLoaderEvent(type, bubbles, cancelable); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/bitly/events/BitLyEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.bitly.events { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class BitLyEvent extends Event { 8 | 9 | // Constants 10 | public static const SUCCESS:String = "onSuccess"; 11 | public static const ERROR:String = "onError"; 12 | 13 | // Properties 14 | protected var _data:Object; 15 | protected var _status_code:int; 16 | protected var _status_txt:String; 17 | 18 | // ================================================================================================================ 19 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 20 | 21 | public function BitLyEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false, __data:Object = null, __status_code:int = 0, __status_txt:String = ""):void { 22 | super(__type, __bubbles, __cancelable); 23 | 24 | _data = __data; 25 | _status_code = __status_code; 26 | _status_txt = __status_txt; 27 | } 28 | 29 | // ================================================================================================================ 30 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 31 | 32 | override public function clone():Event { 33 | return new BitLyEvent(type, bubbles, cancelable, _data, _status_code, _status_txt); 34 | } 35 | 36 | // ================================================================================================================ 37 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 38 | 39 | public function get data():Object { 40 | return _data; 41 | } 42 | 43 | public function get status_code():int { 44 | return _status_code; 45 | } 46 | 47 | public function get status_txt():String { 48 | return _status_txt; 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/QuickButtonPanel.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug { 2 | import flash.display.Sprite; 3 | 4 | /** 5 | * @author zeh fernando 6 | */ 7 | public class QuickButtonPanel extends Sprite { 8 | 9 | // Properties 10 | private var buttons:Vector.; 11 | private var col:int; 12 | private var row:int; 13 | private var buttonWidth:Number; 14 | private var buttonHeight:Number; 15 | private var marginHorizontal:Number; 16 | private var marginVertical:Number; 17 | 18 | // ================================================================================================================ 19 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 20 | 21 | public function QuickButtonPanel(__buttonWidth:Number = 140, __buttonHeight:Number = 35, __marginHorizontal:Number = 10, __marginVertical:Number = 5) { 22 | buttons = new Vector.(); 23 | 24 | buttonWidth = __buttonWidth; 25 | buttonHeight = __buttonHeight; 26 | marginHorizontal = __marginHorizontal; 27 | marginVertical = __marginVertical; 28 | 29 | col = 0; 30 | row = 0; 31 | } 32 | 33 | 34 | // ================================================================================================================ 35 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 36 | 37 | public function addButton(__text:String, __onClick:Function = null):void { 38 | var ix:Number = col * (buttonWidth + marginHorizontal); 39 | var iy:Number = row * (buttonHeight + marginVertical); 40 | 41 | var button:QuickButton = new QuickButton(__text, ix, iy, __onClick, buttonWidth, buttonHeight); 42 | addChild(button); 43 | buttons.push(button); 44 | 45 | row++; 46 | } 47 | 48 | public function addEmptySpace():void { 49 | row++; 50 | } 51 | 52 | public function addNewColumn():void { 53 | col++; 54 | row = 0; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookPage.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class FacebookPage extends FacebookAuthor { 7 | 8 | // http://developers.facebook.com/docs/reference/api/page 9 | 10 | // http://graph.facebook.com/rmstitanicinc 11 | // http://graph.facebook.com/platform 12 | 13 | // Properties 14 | public var category:String; 15 | 16 | public var link:String; 17 | public var username:String; 18 | public var companyOverview:String; 19 | public var mission:String; 20 | public var products:String; 21 | public var fanCount:int; 22 | public var founded:String; // Date? 23 | 24 | // ================================================================================================================ 25 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 26 | 27 | public function FacebookPage() { 28 | super(); 29 | } 30 | 31 | // ================================================================================================================ 32 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 33 | 34 | public static function fromJSONObject(o:Object): FacebookPage { 35 | if (!Boolean(o)) return null; 36 | 37 | var page:FacebookPage = new FacebookPage(); 38 | 39 | page.id = o["id"]; 40 | page.name = o["name"]; 41 | 42 | page.category = o["category"]; 43 | 44 | page.picture = o["picture"]; // Manual setup if supplied 45 | page.link = o["link"]; 46 | page.username = o["username"]; 47 | page.companyOverview = o["companyOverview"]; 48 | page.mission = o["mission"]; 49 | page.products = o["products"]; 50 | page.fanCount = o["fanCount"]; 51 | page.founded = o["founded"]; 52 | page.category = o["category"]; 53 | 54 | return page; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /com/zehfernando/utils/RandomGenerator.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | import flash.geom.Point; 3 | 4 | /** 5 | * @author zeh fernando 6 | */ 7 | public class RandomGenerator { 8 | 9 | // Temp properties for speed 10 | private static var a:Number; 11 | private static var b:Number; 12 | private static var c:Number; 13 | private static var p:Number; 14 | 15 | private static const TWO_PI:Number = 2 * Math.PI; 16 | 17 | public static function getInCircle(__radius:Number):Point { 18 | // http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly 19 | 20 | // Uniform generator (radius-angle would concentrate in middle) 21 | a = Math.random(); 22 | b = Math.random(); 23 | if (a > b) { 24 | c = b; 25 | b = a; 26 | a = c; 27 | } 28 | 29 | p = TWO_PI * a/b; 30 | 31 | return new Point(b * __radius * Math.cos(p), b * __radius * Math.sin(p)); 32 | } 33 | 34 | public static function getInRange(__min:Number, __max:Number):Number { 35 | return __min + Math.random() * (__max-__min); 36 | } 37 | 38 | public static function getInIntegerRange(__min:Number, __max:Number):Number { 39 | return Math.round(__min + Math.random() * (__max-__min)); 40 | } 41 | 42 | public static function getFromVector(__vector:Vector.<*>):Vector.<*> { 43 | return __vector[Math.floor(Math.random() * __vector.length)]; 44 | } 45 | 46 | public static function getFromArray(__array:Array):* { 47 | return __array[Math.floor(Math.random() * __array.length)]; 48 | } 49 | 50 | public static function getColor():uint { 51 | return (Math.random() * 0xffffff) & 0xffffff; 52 | } 53 | 54 | public static function getBoolean():Boolean { 55 | return Math.random() > 0.5; 56 | } 57 | 58 | public static function getFromSeed(__seed:int = -1):Number { 59 | // Return a predictable pseudo-random number (0..0.999) 60 | if (__seed < 0) { 61 | return Math.random(); 62 | } else { 63 | return ((__seed * 1.12836) + 0.7) % 1; 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /com/zehfernando/data/GarbageCan.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data { 2 | import starling.textures.Texture; 3 | 4 | import flash.net.NetStream; 5 | /** 6 | * @author zeh fernando 7 | */ 8 | public class GarbageCan { 9 | 10 | // Gathers stuff to be cleared later 11 | 12 | // Properties 13 | private var items:Array; 14 | 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function GarbageCan() { 20 | items = []; 21 | } 22 | 23 | 24 | // ================================================================================================================ 25 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 26 | 27 | private function removeItem(__item:Object):void { 28 | if (__item is NetStream) removeItemNetStream(__item as NetStream); 29 | if (__item is Texture) removeItemStarlingTexture(__item as Texture); 30 | } 31 | 32 | private function removeItemNetStream(__item:NetStream):void { 33 | __item.close(); 34 | __item.dispose(); 35 | } 36 | 37 | private function removeItemStarlingTexture(__item:Texture):void { 38 | __item.dispose(); 39 | } 40 | 41 | 42 | // ================================================================================================================ 43 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 44 | 45 | public function put(__object:Object):void { 46 | items.push(__object); 47 | } 48 | 49 | public function clearAll():void { 50 | while (items.length > 0) clearOne(); 51 | } 52 | 53 | public function clearOne():void { 54 | if (items.length > 0) removeItem(items.pop()); 55 | // Clean reset - necessary internally? 56 | if (items.length == 0) items = []; 57 | } 58 | 59 | public function get numItems():int { 60 | return items.length; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookTag.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | 3 | import com.zehfernando.net.apis.facebook.FacebookDataUtils; 4 | /** 5 | * @author zeh 6 | */ 7 | public class FacebookTag { 8 | 9 | /* 10 | "tags": { 11 | "data": [ 12 | { 13 | "id": "711322444", 14 | "name": "Zeh Fernando", 15 | "x": 50, 16 | "y": 49, 17 | "created_time": "2011-01-24T00:11:19+0000" 18 | }, 19 | { 20 | "id": "13610420", 21 | "name": "Meagan Palatino", 22 | "x": 37, 23 | "y": 40, 24 | "created_time": "2011-01-24T00:11:19+0000" 25 | } 26 | ] 27 | }, 28 | */ 29 | 30 | // Properties 31 | public var id:String; 32 | public var name:String; 33 | public var x:int; // From 0-100 34 | public var y:int; // From 0-100 35 | public var created:Date; 36 | 37 | 38 | // ================================================================================================================ 39 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 40 | 41 | public function FacebookTag() { 42 | } 43 | 44 | // ================================================================================================================ 45 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 46 | 47 | public static function fromJSONObject(o:Object): FacebookTag { 48 | if (!Boolean(o)) return null; 49 | 50 | var tag:FacebookTag = new FacebookTag(); 51 | 52 | tag.id = o["id"]; 53 | tag.name = o["name"]; 54 | tag.x = o["x"]; 55 | tag.y = o["y"]; 56 | tag.created= FacebookDataUtils.getResultStringAsDate(o["created_time"]); 57 | 58 | return tag; 59 | } 60 | 61 | public static function fromJSONObjectArray(o:Array): Vector. { 62 | var tags:Vector. = new Vector.(); 63 | 64 | if (!Boolean(o)) return tags; 65 | 66 | for (var i:int = 0; i < o.length; i++) { 67 | tags.push(FacebookTag.fromJSONObject(o[i])); 68 | } 69 | 70 | return tags; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /com/zehfernando/display/containers/IVideoContainer.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.containers { 2 | import flash.events.IEventDispatcher; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public interface IVideoContainer extends IEventDispatcher { 8 | 9 | // ================================================================================================================ 10 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 11 | 12 | function playVideo():void; 13 | function pauseVideo():void; 14 | function stopVideo():void; 15 | function playPauseVideo():void; 16 | 17 | function load(__urlOrId:String): void; 18 | function unload(): void; 19 | 20 | function dispose(): void; 21 | 22 | function getMaximumPositionPlayed():Number; 23 | 24 | // ================================================================================================================ 25 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 26 | 27 | function get time(): Number; 28 | function set time(__value:Number): void; 29 | 30 | function get duration(): Number; 31 | 32 | function get position(): Number; 33 | function set position(__value:Number): void; 34 | 35 | function get framerate(): Number; 36 | 37 | function get isPlaying(): Boolean; 38 | 39 | function get autoPlay(): Boolean; 40 | function set autoPlay(__value:Boolean):void; 41 | 42 | function get volume():Number; 43 | function set volume(__value:Number):void; 44 | 45 | function get loop(): Boolean; 46 | function set loop(__value:Boolean):void; 47 | 48 | function get loadedPercent(): Number; 49 | 50 | // 51 | 52 | function get smoothing(): Boolean; 53 | function set smoothing(__value:Boolean):void; 54 | 55 | function get scaleMode(): String; 56 | function set scaleMode(__value:String):void; 57 | 58 | function get width(): Number; 59 | function set width(__value:Number):void; 60 | 61 | function get height(): Number; 62 | function set height(__value:Number):void; 63 | 64 | function get contentWidth(): Number; 65 | 66 | function get contentHeight(): Number; 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /com/zehfernando/display/components/text/UndoManager.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.components.text { 2 | /** 3 | * @author zeh 4 | */ 5 | public class UndoManager { 6 | 7 | // Properties 8 | protected var _currentState:int; 9 | 10 | protected var states:Vector.; 11 | 12 | // ================================================================================================================ 13 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 14 | 15 | public function UndoManager() { 16 | clear(); 17 | } 18 | 19 | // ================================================================================================================ 20 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 21 | 22 | public function getState():Object { 23 | if (_currentState > -1) return states[_currentState]; 24 | 25 | return null; 26 | } 27 | 28 | public function saveState(__state:Object):void { 29 | currentState++; 30 | states[currentState] = __state; 31 | 32 | // Delete additional states 33 | if (states.length > _currentState+1) { 34 | states.splice(_currentState+1, states.length - _currentState - 1); 35 | } 36 | } 37 | 38 | public function clear():void { 39 | states = new Vector.(); 40 | currentState = -1; 41 | } 42 | 43 | public function prevState():Boolean { 44 | if (_currentState > 0) { 45 | _currentState--; 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | public function nextState():Boolean { 52 | if (_currentState < states.length - 1) { 53 | _currentState++; 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | // ================================================================================================================ 60 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 61 | 62 | public function get currentState():int { 63 | return _currentState; 64 | } 65 | public function set currentState(__value:int):void { 66 | if (_currentState != __value) { 67 | _currentState = __value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /com/zehfernando/display/decorators/BlurDecorator.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.decorators { 2 | import flash.display.DisplayObject; 3 | import flash.filters.BlurFilter; 4 | 5 | /** 6 | * @author zeh 7 | */ 8 | public class BlurDecorator extends AbstractDecorator { 9 | 10 | // Properties 11 | protected var _blurX:Number; 12 | protected var _blurY:Number; 13 | protected var _quality:Number; 14 | 15 | protected var _clearIfEmpty:Boolean; 16 | 17 | 18 | // ================================================================================================================ 19 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 20 | 21 | public function BlurDecorator(__target:DisplayObject) { 22 | _blurX = 0; 23 | _blurY = 0; 24 | _quality = 1; 25 | 26 | _clearIfEmpty = true; 27 | 28 | super(__target); 29 | } 30 | 31 | // ================================================================================================================ 32 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 33 | 34 | override protected function apply():void { 35 | _target.filters = (_blurX == 0 && _blurY == 0 && _clearIfEmpty) ? [] : [new BlurFilter(_blurX, _blurY, _quality)]; 36 | } 37 | 38 | // ================================================================================================================ 39 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 40 | 41 | public function get blurX():Number { 42 | return _blurX; 43 | } 44 | public function set blurX(__value:Number):void { 45 | if (_blurX != __value) { 46 | _blurX = __value; 47 | apply(); 48 | } 49 | } 50 | 51 | public function get blurY():Number { 52 | return _blurY; 53 | } 54 | public function set blurY(__value:Number):void { 55 | if (_blurY != __value) { 56 | _blurY = __value; 57 | apply(); 58 | } 59 | } 60 | 61 | public function get quality():Number { 62 | return _quality; 63 | } 64 | public function set quality(__value:Number):void { 65 | if (_quality != __value) { 66 | _quality = __value; 67 | apply(); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /com/zehfernando/net/loaders/VideoLoaderCuePointEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.loaders { 2 | 3 | import flash.events.Event; 4 | /** 5 | * @author zeh 6 | */ 7 | public class VideoLoaderCuePointEvent extends Event { 8 | 9 | // Constants 10 | public static const CUE_POINT:String = "onCuePoint"; 11 | 12 | // Properties 13 | protected var _cuePointTime:Number; 14 | protected var _cuePointName:String; 15 | protected var _cuePointType:String; 16 | protected var _cuePointParameters:Object; 17 | 18 | // ================================================================================================================ 19 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 20 | 21 | public function VideoLoaderCuePointEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false, __cuePointTime:Number = NaN, __cuePointName:String = "", __cuePointType:String = "", __cuePointParameters:Object = ""):void { 22 | super(__type, __bubbles, __cancelable); 23 | 24 | _cuePointTime = __cuePointTime; 25 | _cuePointName = __cuePointName; 26 | _cuePointType = __cuePointType; 27 | _cuePointParameters = __cuePointParameters; 28 | } 29 | 30 | // ================================================================================================================ 31 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 32 | 33 | override public function clone():Event { 34 | return new VideoLoaderCuePointEvent(type, bubbles, cancelable, _cuePointTime, _cuePointName, _cuePointType); 35 | } 36 | 37 | // ================================================================================================================ 38 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 39 | 40 | public function get cuePointTime():Number { 41 | return _cuePointTime; 42 | } 43 | 44 | public function get cuePointName():String { 45 | return _cuePointName; 46 | } 47 | 48 | public function get cuePointType():String { 49 | return _cuePointType; 50 | } 51 | 52 | public function get cuePointParameters():Object { 53 | return _cuePointParameters; 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /com/zehfernando/signals/SimpleSignal.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.signals { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class SimpleSignal { 6 | 7 | // Super-simple signals class inspired by Robert Penner's AS3Signals: 8 | // http://github.com/robertpenner/as3-signals 9 | 10 | // Properties 11 | private var functions:Vector.; 12 | 13 | private var ifr:int; // i for removal (to limit garbage collection) 14 | 15 | // ================================================================================================================ 16 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 17 | 18 | public function SimpleSignal() { 19 | functions = new Vector.(); 20 | } 21 | 22 | // ================================================================================================================ 23 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 24 | 25 | public function add(__function:Function):Boolean { 26 | if (functions.indexOf(__function) == -1) { 27 | functions.push(__function); 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | public function remove(__function:Function):Boolean { 34 | ifr = functions.indexOf(__function); 35 | if (ifr > -1) { 36 | functions.splice(ifr, 1); 37 | return true; 38 | } 39 | return false; 40 | } 41 | 42 | public function removeAll():Boolean { 43 | if (functions.length > 0) { 44 | functions.length = 0; 45 | return true; 46 | } 47 | return false; 48 | } 49 | 50 | public function dispatch(...__args:Array):void { 51 | var functionsDuplicate:Vector. = functions.concat(); 52 | functionsDuplicate.fixed = true; 53 | for (var i:int = 0; i < functionsDuplicate.length; i++) { 54 | functionsDuplicate[i].apply(undefined, __args); 55 | } 56 | } 57 | 58 | 59 | // ================================================================================================================ 60 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 61 | 62 | public function get numItems():uint { 63 | return functions.length; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | My own AS3 frameworks. Used regularly on my own work created for Firstborn or personal projects. 2 | 3 | This has everything put together and a little bit of a cross-dependency between packages (although I try to make packages as self-sufficient as possible). 4 | 5 | Contents of notable importance: 6 | 7 | * `com.zehfernando.net.assets.AssetLibrary` - Dynamic Asset library manager. Used for loading XMLs, JSONs and stuff, and keeping them in memory and accessible in a static context. 8 | 9 | * `com.zehfernando.data.Color` - Helpful color class, for quicker manipulation. 10 | 11 | * `com.zehfernando.models.GameLooper` - A class for proper code looping, especially for games. ENTER_FRAME on steroids. 12 | 13 | * `com.zehfernando.input.binding.KeyActionBinder` - A class for binding more abstract "actions" to Keyboard or GameInput (game controller) events. Used for easier game input in things like the OUYA (uses AIR). Hosted [at its own repository](https://github.com/zeh/key-action-binder), but copied here for reference. 14 | 15 | * `com.zehfernando.display.components.RichTextSprite` - TLE-based rich text element. Powerful, but still lacking some features. 16 | 17 | * `com.zehfernando.display.containers.*` - ImageContainer, VideoContainer, YoutubeVideoContainer, and other containers with a common API for size control and loading/unloading. 18 | 19 | * `com.zehfernando.display.decorators.*` - My decorators, to avoid using a lot of getters/setters or "special" tweenings for objects. 20 | 21 | * `com.zehfernando.display.progressbars.*` - Simple, value-attenuated progress bars. 22 | 23 | * `com.zehfernando.display.shapes.*` - Simple shapes like circles, boxes, triangles and others, for code-based shape building. 24 | 25 | * `com.zehfernando.localization.*` - Classes for external text maintenance and localization. 26 | 27 | * `com.zehfernando.navigation.*` - Classes for internal navigation (SWFAddress). Very much work in progress and still with a few internal hacks. 28 | 29 | * `com.zehfernando.net.*` - Classes for queued loading, and limited APIs for common usage (Bit.Ly, Twitter, Facebook, YouTube, Face.com). 30 | 31 | * `com.zehfernando.utils.*` - Bunch of utils that don't really fit anywhere else now. 32 | 33 | Package names, class locations, and overall structure can and will change at will (I'm refactoring-happy). 34 | -------------------------------------------------------------------------------- /com/zehfernando/display/shapes/Triangle.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.shapes { 2 | import flash.display.Sprite; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class Triangle extends Sprite { 8 | 9 | // Properties 10 | protected var _color:Number; 11 | protected var _length:Number; 12 | protected var _weight:Number; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function Triangle(__length:Number = 100, __weight:Number = 100, __color:int = 0xff0000, __rotation:Number = 0) { 18 | 19 | _color = __color & 0xffffff; 20 | _length = __length; 21 | _weight = __weight; 22 | 23 | rotation = __rotation; 24 | 25 | paint(); 26 | } 27 | 28 | 29 | // ================================================================================================================ 30 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 31 | 32 | protected function paint():void { 33 | graphics.clear(); 34 | graphics.lineStyle(); 35 | graphics.beginFill(_color); 36 | graphics.moveTo(0, -_weight/2); 37 | graphics.lineTo(_length, 0); 38 | graphics.lineTo(0, _weight/2); 39 | graphics.endFill(); 40 | } 41 | 42 | 43 | // ================================================================================================================ 44 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 45 | 46 | public function get color():int { 47 | return _color; 48 | } 49 | public function set color(__value:int):void { 50 | if (_color != __value) { 51 | _color = __value; 52 | paint(); 53 | } 54 | } 55 | 56 | public function get length():Number { 57 | return _length; 58 | } 59 | 60 | public function set length(__value:Number):void { 61 | if (_length != __value) { 62 | _length = __value; 63 | paint(); 64 | } 65 | } 66 | 67 | public function get weight():Number { 68 | return _weight; 69 | } 70 | 71 | public function set weight(__value:Number):void { 72 | if (_weight != __value) { 73 | _weight = __value; 74 | paint(); 75 | } 76 | } 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /com/zehfernando/display/drawPlane.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display { 2 | import flash.display.BitmapData; 3 | import flash.display.Graphics; 4 | import flash.geom.Point; 5 | 6 | /** 7 | * @author zeh 8 | */ 9 | public function drawPlane(graphics:Graphics, bitmap:BitmapData, p1:Point, p2:Point, p3:Point, p4:Point, scaleY:Number = 1, offsetY:Number = 0):void { 10 | var pc:Point = getIntersection(p1, p4, p2, p3); // Central point 11 | 12 | // If no intersection between two diagonals, doesn't draw anything 13 | if (!Boolean(pc)) return; 14 | 15 | // Lengths of first diagonal 16 | var ll1:Number = Point.distance(p1, pc); 17 | var ll2:Number = Point.distance(pc, p4); 18 | 19 | // Lengths of second diagonal 20 | var lr1:Number = Point.distance(p2, pc); 21 | var lr2:Number = Point.distance(pc, p3); 22 | 23 | // Ratio between diagonals 24 | var f:Number = (ll1 + ll2) / (lr1 + lr2); 25 | 26 | // Draws the triangle 27 | graphics.beginBitmapFill(bitmap, null, false, true); 28 | 29 | var ty:Number = (0 + offsetY) / scaleY; 30 | var by:Number = (1 + offsetY) / scaleY; 31 | 32 | graphics.drawTriangles( 33 | Vector.([p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y]), 34 | Vector.([0,1,2, 1,3,2]), 35 | Vector.([0,ty,(1/ll2)*f, 1,ty,(1/lr2), 0,by,(1/lr1), 1,by,(1/ll1)*f]) // Magic 36 | ); 37 | 38 | } 39 | } 40 | 41 | import flash.geom.Point; 42 | function getIntersection(p1:Point, p2:Point, p3:Point, p4:Point): Point { 43 | // Returns a point containing the intersection between two lines 44 | // http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/ 45 | // http://www.gamedev.pastebin.com/f49a054c1 46 | 47 | var a1:Number = p2.y - p1.y; 48 | var b1:Number = p1.x - p2.x; 49 | var a2:Number = p4.y - p3.y; 50 | var b2:Number = p3.x - p4.x; 51 | 52 | var denom:Number = a1 * b2 - a2 * b1; 53 | if (denom == 0) return null; 54 | 55 | var c1:Number = p2.x * p1.y - p1.x * p2.y; 56 | var c2:Number = p4.x * p3.y - p3.x * p4.y; 57 | 58 | var p:Point = new Point((b1 * c2 - b2 * c1)/denom, (a2 * c1 - a1 * c2)/denom); 59 | 60 | if (Point.distance(p, p2) > Point.distance(p1, p2)) return null; 61 | if (Point.distance(p, p1) > Point.distance(p1, p2)) return null; 62 | if (Point.distance(p, p4) > Point.distance(p3, p4)) return null; 63 | if (Point.distance(p, p3) > Point.distance(p3, p4)) return null; 64 | 65 | return p; 66 | } -------------------------------------------------------------------------------- /com/zehfernando/display/shapes/Circle.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.shapes { 2 | import flash.display.Sprite; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class Circle extends Sprite { 8 | 9 | // Properties 10 | protected var _color:Number; 11 | protected var _radius:Number; 12 | protected var _innerRadius:Number; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function Circle(__radius:Number = 100, __color:int = -1, __innerRadius:Number = 0) { 18 | 19 | _color = (__color < 0 ? Math.random() * 0xffffff : __color) & 0xffffff; 20 | _radius = __radius; 21 | _innerRadius = __innerRadius; 22 | 23 | paint(); 24 | } 25 | 26 | 27 | // ================================================================================================================ 28 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 29 | 30 | protected function paint():void { 31 | graphics.clear(); 32 | graphics.lineStyle(); 33 | graphics.beginFill(_color); 34 | graphics.drawCircle(0, 0, _radius); 35 | 36 | if (_innerRadius > 0) graphics.drawCircle(0, 0, _innerRadius); 37 | 38 | graphics.endFill(); 39 | 40 | } 41 | 42 | 43 | // ================================================================================================================ 44 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 45 | 46 | public function get color():int { 47 | return _color; 48 | } 49 | public function set color(__value:int):void { 50 | if (_color != __value) { 51 | _color = __value; 52 | paint(); 53 | } 54 | } 55 | 56 | public function get radius():Number { 57 | return _radius; 58 | } 59 | public function set radius(__value:Number):void { 60 | if (_radius != __value) { 61 | _radius = __value; 62 | paint(); 63 | } 64 | } 65 | 66 | public function get innerRadius():Number { 67 | return _innerRadius; 68 | } 69 | public function set innerRadius(__value:Number):void { 70 | if (_innerRadius != __value) { 71 | _innerRadius = __value; 72 | paint(); 73 | } 74 | } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /com/zehfernando/utils/SocialSharer.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | 3 | /** 4 | * @author zeh 5 | */ 6 | public class SocialSharer { 7 | 8 | // // Constants 9 | // public static const TYPE_TWITTER:String = "twitter"; 10 | // public static const TYPE_FACEBOOK:String = "facebook"; 11 | 12 | // Public vars 13 | // public static var twitterShareURL:String; // Normally http://twitter.com/share?text=text_here&url=[[url]] --- REMEMBER TO URLENCODE PARAMETERS 14 | // public static var facebookShareURL:String; // Normally http://www.facebook.com/share.php?u=[[url]]&t=some_title --- REMEMBER TO URLENCODE PARAMETERS 15 | // public static var shareWindowTarget:String; // Normally _blank 16 | 17 | // public static var parameterURL:String; // Example: "http://coachella.5gum" 18 | 19 | 20 | // ================================================================================================================ 21 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 22 | 23 | public static function share(__serviceURL:String, __windowTarget:String = "_blank"):void { 24 | // Shares the current page on some service 25 | 26 | HTMLUtils.openPopup(__serviceURL, 600, 400, __windowTarget); 27 | } 28 | 29 | public static function shareWithVars(__serviceURL:String, __shareText:String, __siteURL:String, __windowTarget:String = "_blank"):void { 30 | // Shares the current page on some service 31 | 32 | var url:String = __serviceURL; 33 | 34 | url = url.split("{url}").join(StringUtils.URLEncode(__siteURL)); 35 | url = url.split("{text}").join(StringUtils.URLEncode(__shareText)); 36 | 37 | HTMLUtils.openPopup(url, 600, 400, __windowTarget); 38 | } 39 | 40 | // public static function share(__type:String):void { 41 | // // Shares the current page on some service 42 | // 43 | // var _url:String; 44 | // //var _trackId:String; 45 | // 46 | // switch(__type) { 47 | // case TYPE_TWITTER: 48 | // _url = twitterShareURL; 49 | // break; 50 | // case TYPE_FACEBOOK: 51 | // _url = facebookShareURL; 52 | // break; 53 | // default: 54 | // trace("SocialSharer :: ERROR! Tried sharing via unknown type [" + __type + "]!"); 55 | // return; 56 | // } 57 | // 58 | // _url = _url.split("[[url]]").join(StringUtils.URLEncode(parameterURL)); 59 | // 60 | // HTMLUtils.openPopup(_url, 600, 400, shareWindowTarget); 61 | // } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /com/zehfernando/navigation/NavigableSpriteEvent.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.navigation { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class NavigableSpriteEvent extends Event { 8 | 9 | // Enums 10 | public static const OPENING:String = "onOpening"; // A NavigableSprite is about to start opening 11 | public static const OPENED:String = "onOpened"; // A NavigableSprite has finished opening 12 | public static const CLOSING:String = "onClosing"; // A NavigableSprite is about to start closing 13 | public static const CLOSED:String = "onClosed"; // A NavigableSprite has finished closing 14 | 15 | public static const OPENING_CHILD:String = "onOpeningChild"; // Implemented; test 16 | public static const OPENED_CHILD:String = "onOpenedChild"; // Implemented; test 17 | public static const CLOSING_CHILD:String = "onClosingChild"; // Implemented; test 18 | public static const CLOSED_CHILD:String = "onClosedChild"; // Implemented; test 19 | 20 | public static const ALLOWED_TO_OPEN:String = "allowedToOpen"; // Permission is given to call open() on this sprite 21 | public static const ALLOWED_TO_CLOSE:String = "allowedToClose"; // Permission is given to call close() on this sprite 22 | 23 | public static const ALLOWED_TO_PRE_OPEN_CHILD:String = "allowedToPreOpenChild"; // Permission is given to PRE-OPEN (create) a child 24 | public static const ALLOWED_TO_OPEN_CHILD:String = "allowedToOpenChild"; // Permission is given to call open() on a child 25 | public static const ALLOWED_TO_CLOSE_CHILD:String = "allowedToCloseChild"; // Permission is given to call close() on a child 26 | 27 | // ================================================================================================================ 28 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 29 | 30 | public function NavigableSpriteEvent(__type:String, __bubbles:Boolean = false, __cancelable:Boolean = false) { 31 | super(__type, __bubbles, __cancelable); 32 | } 33 | 34 | // ================================================================================================================ 35 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 36 | 37 | override public function clone(): Event { 38 | return new NavigableSpriteEvent(type, bubbles, cancelable); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /com/zehfernando/data/ObjectPool.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.data { 2 | /** 3 | * @author zeh fernando 4 | */ 5 | public class ObjectPool { 6 | 7 | private var objects:Array; 8 | private var objectsUsed:Vector.; 9 | 10 | private var numObjectsFree:int; 11 | 12 | public var create:Function; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function ObjectPool() { 18 | objects = []; 19 | objectsUsed = new Vector.(); 20 | numObjectsFree = 0; 21 | } 22 | 23 | // ================================================================================================================ 24 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 25 | 26 | public function get():* { 27 | // Returns an unused object from the existing pool, or creating a new if none is available 28 | if (numObjectsFree == 0) { 29 | // No objects free, create a new one 30 | if (create != null) { 31 | var obj:* = create(); 32 | objects.push(obj); 33 | objectsUsed.push(true); 34 | return obj; 35 | } else { 36 | return null; 37 | } 38 | } else { 39 | // Find first unused object 40 | for (var i:int = 0; i < objectsUsed.length; i++) { 41 | if (!objectsUsed[i]) { 42 | // This is not used 43 | objectsUsed[i] = true; 44 | numObjectsFree--; 45 | return objects[i]; 46 | } 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | public function put(__object:*):void { 53 | // Put an object back in the pool 54 | var index:int = objects.indexOf(__object); 55 | if (index > -1) { 56 | // Object is in the pool, just put it back 57 | objectsUsed[index] = false; 58 | numObjectsFree++; 59 | } else { 60 | // Object is not in the pool yet, add it 61 | objects.push(__object); 62 | objectsUsed.push(false); 63 | numObjectsFree++; 64 | } 65 | } 66 | 67 | public function clear():void { 68 | objects.length = 0; 69 | objectsUsed.length = 0; 70 | numObjectsFree = 0; 71 | } 72 | 73 | public function getNumObjectsFree():int { 74 | return numObjectsFree; 75 | } 76 | 77 | public function getNumObjects():int { 78 | return objects.length; 79 | } 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/BasicFacebookRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.BasicServiceRequest; 3 | import com.zehfernando.net.apis.facebook.auth.FacebookAuth; 4 | import com.zehfernando.net.apis.facebook.events.FacebookServiceEvent; 5 | import com.zehfernando.utils.console.log; 6 | 7 | import flash.events.Event; 8 | import flash.events.IOErrorEvent; 9 | import flash.events.SecurityErrorEvent; 10 | import flash.net.URLVariables; 11 | 12 | /** 13 | * @author zeh 14 | */ 15 | public class BasicFacebookRequest extends BasicServiceRequest { 16 | 17 | // ================================================================================================================ 18 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 19 | 20 | public function BasicFacebookRequest() { 21 | super(); 22 | } 23 | 24 | // ================================================================================================================ 25 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 26 | 27 | override protected function getData():Object { 28 | var vars:URLVariables = new URLVariables(); 29 | 30 | if (FacebookAuth.loggedIn || FacebookAuth.hasAppAccessToken) vars["access_token"] = FacebookAuth.accessToken; 31 | 32 | return vars; 33 | } 34 | 35 | // ================================================================================================================ 36 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 37 | 38 | override protected function onSecurityError(e:SecurityErrorEvent):void { 39 | log("Security error while loading " + requestURL); 40 | super.onSecurityError(e); 41 | dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.ERROR)); 42 | } 43 | 44 | override protected function onIOError(e:IOErrorEvent):void { 45 | log("IO Error while loading " + requestURL + " - are you sure an access token is available?"); 46 | log(loader.data); 47 | super.onIOError(e); 48 | dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.ERROR)); 49 | } 50 | 51 | override protected function onComplete(e:Event):void { 52 | super.onComplete(e); 53 | dispatchEvent(new FacebookServiceEvent(FacebookServiceEvent.COMPLETE)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /com/zehfernando/utils/tracking/DARTUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.tracking { 2 | import com.zehfernando.utils.AppUtils; 3 | import flash.display.Loader; 4 | import flash.events.IOErrorEvent; 5 | import flash.external.ExternalInterface; 6 | import flash.net.URLRequest; 7 | 8 | /** 9 | * @author Zeh Fernando 10 | */ 11 | public class DARTUtils { 12 | 13 | // Properties 14 | protected static var inited:Boolean; 15 | protected static var testMode:Boolean; 16 | 17 | // ================================================================================================================ 18 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 19 | 20 | public function DARTUtils() { 21 | throw new Error("You cannot initialize this class"); 22 | } 23 | 24 | // ================================================================================================================ 25 | // STATIC functions ----------------------------------------------------------------------------------------------- 26 | 27 | public static function init():void { 28 | if (!inited) { 29 | inited = true; 30 | if (!AppUtils.isDebugSWF()) { 31 | trace ("DARTUtils :: init :: LIVE mode :: ExternalInterface.available = " + ExternalInterface.available); 32 | testMode = false; 33 | } else { 34 | //trace ("DARTUtils :: init :: TEST mode"); 35 | testMode = true; 36 | } 37 | } 38 | } 39 | 40 | public static function trackPageView(__tag:String):void { 41 | if (!inited) return; 42 | 43 | if (__tag == "") return; 44 | 45 | // Below code comes from DART themselves (with small changes) 46 | var ldr:Loader = new Loader(); 47 | var rnd:Number = Math.floor(Math.random() * 1000000000); 48 | var url:String = __tag.replace("[rnd]", rnd.toString(10)); 49 | //var url:String = "http://ad.doubleclick.net/activity;src=1234567;type=group123;cat=trans123;ord="+ rnd +"?"; 50 | var urlReq:URLRequest = new URLRequest(url); 51 | ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false,0, true); 52 | ldr.load(urlReq); 53 | 54 | //if (!testMode) { 55 | //ExternalInterface.call("dcsMultiTrack", WT_PARAMETER_URI, __uri, WT_PARAMETER_TITLE, __title); 56 | //} 57 | 58 | if (testMode) { 59 | trace ("DARTUtils :: trackPageView :: " + url); 60 | } 61 | 62 | } 63 | 64 | protected static function onError(e:IOErrorEvent):void { 65 | // To catch error message due to DART's loading of invalid content 66 | trace ("GAUtils :: IOError :: ["+e+"]"); 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /com/zehfernando/utils/RenderUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | import flash.events.Event; 3 | 4 | /** 5 | * @author zeh 6 | */ 7 | public class RenderUtils { 8 | 9 | // Properties 10 | protected static var functionsToCall:Vector. = new Vector.(); 11 | 12 | // Create functions that are called prior to rendering 13 | protected static var isQueued:Boolean; 14 | 15 | // ================================================================================================================ 16 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 17 | 18 | protected static function invalidate():void { 19 | AppUtils.getStage().invalidate(); 20 | } 21 | 22 | protected static function queue():void { 23 | if (!isQueued) { 24 | AppUtils.getStage().addEventListener(Event.RENDER, onRenderStage); 25 | isQueued = true; 26 | } 27 | } 28 | 29 | protected static function executeQueue():void { 30 | unQueue(); 31 | 32 | // for (var i:int = 0; i < functionsToCall.length; i++) { 33 | // functionsToCall.unshift[i](); 34 | // } 35 | while (functionsToCall.length > 0) { 36 | functionsToCall.shift()(); 37 | } 38 | 39 | functionsToCall = new Vector.(); 40 | } 41 | 42 | protected static function unQueue():void { 43 | if (isQueued) { 44 | AppUtils.getStage().removeEventListener(Event.RENDER, onRenderStage); 45 | isQueued = false; 46 | } 47 | } 48 | 49 | 50 | // ================================================================================================================ 51 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 52 | 53 | protected static function onRenderStage(e:Event):void { 54 | executeQueue(); 55 | } 56 | 57 | 58 | // ================================================================================================================ 59 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 60 | 61 | public static function addFunction(__function:Function):void { 62 | // __function(); 63 | // return; 64 | if (functionsToCall.indexOf(__function) == -1) { 65 | // Doesn't exist, so adds to the stack 66 | functionsToCall.push(__function); 67 | } else { 68 | // Exists, so moves to the end of the list 69 | functionsToCall.splice(functionsToCall.indexOf(__function), 1); 70 | functionsToCall.push(__function); 71 | } 72 | 73 | queue(); 74 | invalidate(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /com/zehfernando/display/ImageAnalyzer.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display { 2 | 3 | import com.zehfernando.data.types.Color; 4 | 5 | import flash.display.BitmapData; 6 | import flash.geom.Rectangle; 7 | /** 8 | * @author zeh 9 | */ 10 | public class ImageAnalyzer { 11 | 12 | // Computes the light from a BitmapData image, based on histogram... max color, min color, average color 13 | // TODO: Ugh, create a better API for this 14 | 15 | // Properties 16 | protected var _min:Color; 17 | protected var _max:Color; 18 | protected var _average:Color; 19 | 20 | // ================================================================================================================ 21 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 22 | 23 | public function ImageAnalyzer(__bitmapData:BitmapData, __rect:Rectangle = null) { 24 | 25 | var hstg:Vector.> = __bitmapData.histogram(__rect); 26 | var i:int, j:int; 27 | var tot:Number; // Total color 28 | var items:Number; // Number of items 29 | var cmin:Number; 30 | var cmax:Number; 31 | 32 | var population:int; 33 | 34 | _min = new Color(); 35 | _max = new Color(); 36 | _average = new Color(); 37 | 38 | for (i = 0; i < 4; i++) { 39 | tot = 0; 40 | items = 0; 41 | cmin = 255; 42 | cmax = 0; 43 | for (j = 0; j < 256; j++) { 44 | population = hstg[i][j]; 45 | items += population; 46 | tot += population * j; 47 | 48 | if (population > 0 && j < cmin) cmin = j; 49 | 50 | if (population > 0 && j > cmax) cmax = j; 51 | } 52 | 53 | switch(i) { 54 | case 0: 55 | _min.r = cmin/255; 56 | _max.r = cmax/255; 57 | _average.r = tot/items/255; 58 | break; 59 | case 1: 60 | _min.g = cmin/255; 61 | _max.g = cmax/255; 62 | _average.g = tot/items/255; 63 | break; 64 | case 2: 65 | _min.b = cmin/255; 66 | _max.b = cmax/255; 67 | _average.b = tot/items/255; 68 | break; 69 | case 3: 70 | _min.a = cmin/255; 71 | _max.a = cmax/255; 72 | _average.a = tot/items/255; 73 | break; 74 | } 75 | } 76 | 77 | // Luma values - http://www.faqs.org/faqs/graphics/colorspace-faq/ 78 | // var cavg:Number = avg[0] * 0.212671 + avg[1] * 0.71516 + avg[2] * 0.072169; 79 | } 80 | 81 | public function get min():Color { 82 | return _min; 83 | } 84 | 85 | public function get max():Color { 86 | return _max; 87 | } 88 | 89 | public function get average():Color { 90 | return _average; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /com/zehfernando/display/abstracts/ResizableSprite.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.abstracts { 2 | import flash.display.Sprite; 3 | import flash.events.Event; 4 | 5 | /** 6 | * @author zeh 7 | */ 8 | public class ResizableSprite extends Sprite { 9 | 10 | // Properties 11 | protected var _width:Number; 12 | protected var _height:Number; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function ResizableSprite() { 18 | _width = 100; 19 | _height = 100; 20 | 21 | addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); 22 | addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true); 23 | } 24 | 25 | 26 | // ================================================================================================================ 27 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 28 | 29 | protected function redrawWidth():void { 30 | throw new Error("Error: the method redrawWidth() of ResizableSprite has to be overridden."); 31 | } 32 | 33 | protected function redrawHeight():void { 34 | throw new Error("Error: the method redrawHeight() of ResizableSprite has to be overridden."); 35 | } 36 | 37 | 38 | // ================================================================================================================ 39 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 40 | 41 | protected function onAddedToStage(__e:Event):void { 42 | redrawWidth(); 43 | redrawHeight(); 44 | } 45 | 46 | protected function onRemovedFromStage(__e:Event):void { 47 | } 48 | 49 | 50 | // ================================================================================================================ 51 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 52 | 53 | override public function get width():Number { 54 | return _width; 55 | } 56 | override public function set width(__value:Number):void { 57 | if (_width != __value) { 58 | _width = __value; 59 | redrawWidth(); 60 | } 61 | } 62 | 63 | override public function get height():Number { 64 | return _height; 65 | } 66 | override public function set height(__value:Number):void { 67 | if (_height != __value) { 68 | _height = __value; 69 | redrawHeight(); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookAuthor.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | 3 | import com.zehfernando.net.apis.facebook.FacebookConstants; 4 | 5 | /** 6 | * @author zeh 7 | */ 8 | public class FacebookAuthor { 9 | 10 | // Properties 11 | public var id:String; 12 | public var name:String; 13 | 14 | protected var _picture:String; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function FacebookAuthor() { 20 | } 21 | 22 | // ================================================================================================================ 23 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 24 | 25 | public static function fromJSONObject(o:Object): FacebookAuthor { 26 | if (!Boolean(o)) return null; 27 | 28 | var author:FacebookAuthor; 29 | 30 | if (Boolean(o["category"])) { 31 | // It's a page 32 | author = FacebookPage.fromJSONObject(o); 33 | } else { 34 | // It's a normal user 35 | author = FacebookUser.fromJSONObject(o); 36 | } 37 | 38 | return author; 39 | } 40 | 41 | // ================================================================================================================ 42 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 43 | 44 | public function get pictureLarge():String { 45 | // 200 pixels wide, variable height 46 | return (FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_FILE_PICTURE_LARGE).replace(FacebookConstants.PARAMETER_AUTHOR_ID, id); 47 | } 48 | 49 | public function get pictureNormal():String { 50 | // 100x100 51 | return (FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_FILE_PICTURE_NORMAL).replace(FacebookConstants.PARAMETER_AUTHOR_ID, id); 52 | } 53 | 54 | public function get picture():String { 55 | // // 50x50, zoomed (same as square) 56 | // If the direct link to the profile picture has been supplied, use it. If not, use the service that redirects to the picture 57 | return Boolean (_picture) ? _picture : (FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_FILE_PICTURE).replace(FacebookConstants.PARAMETER_AUTHOR_ID, id); 58 | } 59 | 60 | // Ugh, error on people without profiles -- tries to load an image from http://static.ak.fbcdn.net/rsrc.php/yL/r/HsTZSDw4avx.gif?type=large 61 | // TODO: auto-detect this, somehow? 62 | 63 | 64 | public function set picture(picture:String):void { 65 | _picture = picture; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookFeedItemRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookFeedPost; 4 | import com.zehfernando.utils.console.log; 5 | 6 | import flash.events.Event; 7 | import flash.net.URLRequestMethod; 8 | /** 9 | * @author zeh at zehfernando.com 10 | */ 11 | public class FacebookFeedItemRequest extends BasicFacebookRequest { 12 | 13 | // Gets data on one single wall item 14 | 15 | // Properties 16 | protected var _itemId:String; 17 | 18 | // Results 19 | protected var _item:FacebookFeedPost; 20 | 21 | // ================================================================================================================ 22 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 23 | 24 | public function FacebookFeedItemRequest() { 25 | super(); 26 | 27 | // Basic service configuration 28 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_FEED_ITEM; 29 | requestMethod = URLRequestMethod.GET; 30 | 31 | // Parameters 32 | // http://developers.facebook.com/docs/reference/api/page 33 | 34 | _itemId = ""; 35 | 36 | } 37 | 38 | // ================================================================================================================ 39 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 40 | 41 | override protected function onComplete(e:Event):void { 42 | var response:Object = JSON.parse(loader.data); 43 | 44 | log ("--> " + response); 45 | //_item = FacebookFeedPost.fromJSONObject(response["data"]); 46 | 47 | super.onComplete(e); 48 | } 49 | 50 | // ================================================================================================================ 51 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 52 | 53 | override public function execute():void { 54 | requestURL = requestURL.replace(FacebookConstants.PARAMETER_ITEM_ID, _itemId); 55 | super.execute(); 56 | } 57 | 58 | // ================================================================================================================ 59 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 60 | 61 | // Parameters 62 | 63 | public function get itemId():String { 64 | return _itemId; 65 | } 66 | public function set itemId(__value:String):void { 67 | _itemId = __value; 68 | } 69 | 70 | // Results 71 | 72 | public function get item(): FacebookFeedPost { 73 | return _item; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/data/FacebookAlbum.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.data { 2 | 3 | import com.zehfernando.net.apis.facebook.FacebookDataUtils; 4 | 5 | /** 6 | * @author zeh 7 | */ 8 | public class FacebookAlbum { 9 | 10 | // http://developers.facebook.com/docs/reference/api/album 11 | // https://graph.facebook.com/143423629024057 12 | 13 | // Properties 14 | public var id:String; 15 | public var from:FacebookAuthor; 16 | public var name:String; 17 | public var description:String; 18 | public var location:String; 19 | public var link:String; 20 | public var numPhotos:String; 21 | public var created:Date; 22 | public var updated:Date; 23 | public var numComments:int; 24 | public var comments:Vector.; 25 | public var type:String; 26 | public var canUpload:Boolean; 27 | public var coverPhoto:String; // id 28 | 29 | // ================================================================================================================ 30 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 31 | 32 | public function FacebookAlbum() { 33 | } 34 | 35 | // ================================================================================================================ 36 | // STATIC INTERFACE ----------------------------------------------------------------------------------------------- 37 | 38 | public static function fromJSONObject(o:Object): FacebookAlbum { 39 | if (!Boolean(o)) return null; 40 | 41 | var album:FacebookAlbum = new FacebookAlbum(); 42 | 43 | album.id = o["id"]; 44 | album.from = FacebookAuthor.fromJSONObject(o["from"]); /// ************* 45 | album.name = o["name"]; 46 | album.description = o["description"]; 47 | album.location = o["location"]; 48 | album.link = o["link"]; 49 | album.created = FacebookDataUtils.getResultStringAsDate(o["created_time"]); 50 | album.updated = FacebookDataUtils.getResultStringAsDate(o["updated_time"]); 51 | album.numComments = Boolean(o["comments"]) ? o["comments"]["count"] : 0; 52 | album.comments = Boolean(o["comments"]) ? FacebookComment.fromJSONObjectArray(o["comments"]["data"]) : new Vector.(); 53 | album.numPhotos = o["count"]; 54 | album.type = o["type"]; 55 | album.canUpload = Boolean(o["can_upload"]); 56 | album.coverPhoto = o["cover_photo"]; 57 | 58 | return album; 59 | } 60 | 61 | public static function fromJSONObjectArray(o:Array): Vector. { 62 | var albums:Vector. = new Vector.(); 63 | 64 | if (!Boolean(o)) return albums; 65 | 66 | for (var i:int = 0; i < o.length; i++) { 67 | albums.push(FacebookAlbum.fromJSONObject(o[i])); 68 | } 69 | 70 | return albums; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /com/zehfernando/navigation/ResizableNavigableSprite.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.navigation { 2 | 3 | import flash.events.Event; 4 | 5 | /** 6 | * @author zeh 7 | */ 8 | public class ResizableNavigableSprite extends NavigableSprite { 9 | 10 | // Properties 11 | protected var _width:Number; 12 | protected var _height:Number; 13 | 14 | // Ugh 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function ResizableNavigableSprite() { 20 | super(); 21 | 22 | _width = 100; 23 | _height = 100; 24 | 25 | addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); 26 | } 27 | 28 | // ================================================================================================================ 29 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 30 | 31 | protected function redrawWidth():void { 32 | for (var i:int = 0; i < createdChildren.length; i++) { 33 | if (createdChildren[i].parent == _childrenContainer) createdChildren[i].width = _width; 34 | } 35 | } 36 | 37 | protected function redrawHeight():void { 38 | for (var i:int = 0; i < createdChildren.length; i++) { 39 | if (createdChildren[i].parent == _childrenContainer) createdChildren[i].height = _height; 40 | } 41 | } 42 | 43 | override protected function createChild(__stub:String): NavigableSprite { 44 | var ns:NavigableSprite = super.createChild(__stub); 45 | if (Boolean(ns)) { 46 | redrawWidth(); 47 | redrawHeight(); 48 | } 49 | return ns; 50 | } 51 | 52 | // ================================================================================================================ 53 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 54 | 55 | protected function onAddedToStage(e:Event):void { 56 | redrawWidth(); 57 | redrawHeight(); 58 | } 59 | 60 | 61 | // ================================================================================================================ 62 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 63 | 64 | override public function get width():Number { 65 | return _width; 66 | } 67 | override public function set width(__value:Number):void { 68 | if (_width != __value) { 69 | _width = __value; 70 | redrawWidth(); 71 | } 72 | } 73 | 74 | override public function get height():Number { 75 | return _height; 76 | } 77 | override public function set height(__value:Number):void { 78 | if (_height != __value) { 79 | _height = __value; 80 | redrawHeight(); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/services/YouTubeVideoInfoRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube.services { 2 | 3 | import com.zehfernando.net.apis.BasicServiceRequest; 4 | import com.zehfernando.net.apis.youtube.YouTubeConstants; 5 | import com.zehfernando.net.apis.youtube.data.YouTubeVideo; 6 | import com.zehfernando.net.apis.youtube.events.YouTubeServiceEvent; 7 | 8 | import flash.events.Event; 9 | import flash.events.IOErrorEvent; 10 | import flash.events.SecurityErrorEvent; 11 | import flash.net.URLRequestMethod; 12 | 13 | /** 14 | * @author zeh 15 | */ 16 | public class YouTubeVideoInfoRequest extends BasicServiceRequest { 17 | 18 | // Properties 19 | protected var _videoId:String; 20 | 21 | // Results 22 | protected var _video:YouTubeVideo; 23 | 24 | // ================================================================================================================ 25 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 26 | 27 | public function YouTubeVideoInfoRequest() { 28 | super(); 29 | 30 | // Basic service configuration 31 | requestURL = YouTubeConstants.DOMAIN + YouTubeConstants.SERVICE_VIDEO_INFO; 32 | requestMethod = URLRequestMethod.GET; 33 | 34 | // Parameters 35 | 36 | _videoId = ""; 37 | } 38 | 39 | // ================================================================================================================ 40 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 41 | 42 | override protected function onSecurityError(e:SecurityErrorEvent):void { 43 | super.onSecurityError(e); 44 | dispatchEvent(new YouTubeServiceEvent(YouTubeServiceEvent.ERROR)); 45 | } 46 | 47 | override protected function onIOError(e:IOErrorEvent):void { 48 | super.onIOError(e); 49 | dispatchEvent(new YouTubeServiceEvent(YouTubeServiceEvent.ERROR)); 50 | } 51 | 52 | override protected function onComplete(e:Event):void { 53 | _video = YouTubeVideo.fromXML(new XML(loader.data)); 54 | 55 | super.onComplete(e); 56 | dispatchEvent(new YouTubeServiceEvent(YouTubeServiceEvent.COMPLETE)); 57 | } 58 | 59 | 60 | override public function execute():void { 61 | requestURL = requestURL.replace(YouTubeConstants.PARAMETER_VIDEO_ID, _videoId); 62 | super.execute(); 63 | } 64 | 65 | // ================================================================================================================ 66 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 67 | 68 | // Parameters 69 | 70 | public function get videoId():String { 71 | return _videoId; 72 | } 73 | public function set videoId(__value:String):void { 74 | _videoId = __value; 75 | } 76 | 77 | // Results 78 | 79 | public function get video(): YouTubeVideo { 80 | // TODO: clone? 81 | return _video; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /com/zehfernando/utils/VectorUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils { 2 | /** 3 | * @author zeh at zehfernando.com 4 | */ 5 | public class VectorUtils { 6 | 7 | // Array to vector 8 | 9 | public static function arrayToBooleanVector(__array:Array):Vector. { 10 | var v:Vector. = new Vector.(); 11 | if (Boolean(__array)) { 12 | for (var i:int = 0; i < __array.length; i++) v.push(__array[i]); 13 | } 14 | return v; 15 | } 16 | 17 | public static function arrayToNumberVector(__array:Array):Vector. { 18 | var v:Vector. = new Vector.(); 19 | if (Boolean(__array)) { 20 | for (var i:int = 0; i < __array.length; i++) v.push(__array[i]); 21 | } 22 | return v; 23 | } 24 | 25 | public static function arrayToStringVector(__array:Array):Vector. { 26 | var v:Vector. = new Vector.(); 27 | if (Boolean(__array)) { 28 | for (var i:int = 0; i < __array.length; i++) v.push(__array[i]); 29 | } 30 | return v; 31 | } 32 | 33 | // Vector to array 34 | 35 | public static function booleanVectorToArray(__vector:Vector.):Array { 36 | var l:Array = []; 37 | if (Boolean(__vector)) { 38 | for (var i:int = 0; i < __vector.length; i++) l.push(__vector[i]); 39 | } 40 | return l; 41 | } 42 | 43 | public static function numberVectorToArray(__vector:Vector.):Array { 44 | var l:Array = []; 45 | if (Boolean(__vector)) { 46 | for (var i:int = 0; i < __vector.length; i++) l.push(__vector[i]); 47 | } 48 | return l; 49 | } 50 | 51 | public static function stringVectorToArray(__vector:Vector.):Array { 52 | var l:Array = []; 53 | if (Boolean(__vector)) { 54 | for (var i:int = 0; i < __vector.length; i++) l.push(__vector[i]); 55 | } 56 | return l; 57 | } 58 | 59 | // String to Vector 60 | 61 | public static function stringToStringVector(__string:String, __separator:String):Vector. { 62 | var v:Vector. = new Vector.(); 63 | if (Boolean(__string && __string.length > 0)) { 64 | var stringList:Array = __string.split(__separator); 65 | for (var i:int = 0; i < stringList.length; i++) v.push(stringList[i]); 66 | } 67 | return v; 68 | } 69 | 70 | // Other 71 | 72 | public static function getEquivalentItemFromNumberVector(__pos:Number, __max:int, __numbers:Vector., __average:Boolean = true):Number { 73 | // Return an item from a number list mapped from the index of another list 74 | if (!__average) { 75 | // Don't allow average, just find a number 76 | return __numbers[Math.round(MathUtils.map(__pos, 0, __max, 0, __numbers.length - 1))]; 77 | } else { 78 | // Allow average, find the two nearest items and use it 79 | var pos:Number = MathUtils.map(__pos, 0, __max, 0, __numbers.length - 1); 80 | var pos1:int = Math.floor(pos); 81 | var pos2:int = Math.min(pos1 + 1, __numbers.length - 1); 82 | return MathUtils.map(pos - pos1, 0, 1, __numbers[pos1], __numbers[pos2], true); 83 | } 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /com/zehfernando/net/assets/AssetType.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.assets { 2 | 3 | /** 4 | * @author Zeh 5 | */ 6 | public class AssetType { 7 | 8 | // Constants 9 | public static const CSS:String = "css"; 10 | public static const XML:String = "xml"; 11 | public static const JSON:String = "json"; 12 | public static const IMAGE:String = "image"; 13 | public static const BINARY:String = "binary"; 14 | public static const SWF:String = "swf"; 15 | public static const VIDEO:String = "video"; 16 | 17 | // ================================================================================================================ 18 | // STATIC functions ----------------------------------------------------------------------------------------------- 19 | 20 | public static function getTypes(): Vector. { 21 | var types:Vector. = new Vector.(); 22 | types.push(AssetType.CSS); 23 | types.push(AssetType.XML); 24 | types.push(AssetType.JSON); 25 | types.push(AssetType.IMAGE); 26 | types.push(AssetType.BINARY); 27 | types.push(AssetType.SWF); 28 | types.push(AssetType.VIDEO); 29 | 30 | return types; 31 | } 32 | 33 | public static function getExtensions(__type:String): Vector. { 34 | // TODO: use dictionaries/vectors of info classes/something that makes more sense 35 | 36 | var vv:Vector. = new Vector.(); 37 | 38 | switch (__type) { 39 | case AssetType.CSS: 40 | vv.push("css"); 41 | break; 42 | case AssetType.XML: 43 | vv.push("xml"); 44 | vv.push("svg"); 45 | break; 46 | case AssetType.JSON: 47 | vv.push("json"); 48 | break; 49 | case AssetType.IMAGE: 50 | vv.push("jpg"); 51 | vv.push("jpeg"); 52 | vv.push("gif"); 53 | vv.push("png"); 54 | break; 55 | case AssetType.BINARY: 56 | vv.push("atf"); 57 | break; 58 | case AssetType.SWF: 59 | vv.push("swf"); 60 | break; 61 | case AssetType.VIDEO: 62 | vv.push("flv"); 63 | vv.push("f4v"); 64 | vv.push("mov"); 65 | vv.push("mp4"); 66 | break; 67 | } 68 | 69 | return vv; 70 | } 71 | 72 | public static function getFromURL(__url:String):String { 73 | // Based on the extension of an URL file, return the type 74 | // TODO: must test for querystrings! 75 | // TODO: must test for other URLs with dots on them! 76 | 77 | var lastDot:Number = 0; 78 | while (__url.indexOf(".", lastDot+1) > -1) { 79 | lastDot = __url.indexOf(".", lastDot+1); 80 | } 81 | __url = __url.substr(lastDot); 82 | 83 | var extSearch:RegExp = /\.([A-Za-z0-9]+)(\?*|)/i; 84 | var result:Object = extSearch.exec(__url); 85 | //trace ("search [" + __url + "] = " + result + " @ " + (Boolean(result) ? result.index : null)); 86 | var extension:String; 87 | extension = Boolean(result) ? result[1] : ""; 88 | 89 | var types:Vector. = getTypes(); 90 | var i:int; 91 | for (i = 0; i < types.length; i++) { 92 | if (getExtensions(types[i]).indexOf(extension) > -1) { 93 | return types[i]; 94 | } 95 | } 96 | 97 | return ""; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /com/zehfernando/display/abstracts/ButtonSprite.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.abstracts { 2 | import flash.display.Sprite; 3 | import flash.events.Event; 4 | import flash.events.MouseEvent; 5 | 6 | /** 7 | * @author zeh 8 | */ 9 | public class ButtonSprite extends Sprite { 10 | 11 | // Properties 12 | protected var _mouseFocus:Number; 13 | protected var _enabled:Number; 14 | protected var _visibility:Number; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function ButtonSprite() { 20 | _mouseFocus = 0; 21 | _enabled = 1; 22 | _visibility = 1; 23 | 24 | mouseChildren = false; 25 | buttonMode = true; 26 | 27 | addEventListener(MouseEvent.ROLL_OVER, onRollOver, false, 0, true); 28 | addEventListener(MouseEvent.ROLL_OUT, onRollOut, false, 0, true); 29 | 30 | addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); 31 | } 32 | 33 | 34 | // ================================================================================================================ 35 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 36 | 37 | protected function redrawState():void { 38 | throw new Error("Error: the method redrawState() of ButtonSprite has to be overridden."); 39 | } 40 | 41 | protected function redrawVisibility():void { 42 | alpha = _visibility; 43 | visible = _visibility > 0; 44 | 45 | mouseEnabled = mouseChildren = _visibility == 1; 46 | } 47 | 48 | // ================================================================================================================ 49 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 50 | 51 | protected function onAddedToStage(e:Event):void { 52 | redrawState(); 53 | redrawVisibility(); 54 | } 55 | 56 | protected function onRollOver(e:MouseEvent):void { 57 | if (enabled >= 1) mouseFocus = 1; 58 | } 59 | 60 | protected function onRollOut(e:MouseEvent):void { 61 | mouseFocus = 0; 62 | } 63 | 64 | // ================================================================================================================ 65 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 66 | 67 | public function get mouseFocus():Number { 68 | return _mouseFocus; 69 | } 70 | public function set mouseFocus(__value:Number):void { 71 | if (_mouseFocus != __value) { 72 | _mouseFocus = __value; 73 | redrawState(); 74 | } 75 | } 76 | 77 | public function get enabled():Number { 78 | return _enabled; 79 | } 80 | public function set enabled(__value:Number):void { 81 | if (_enabled != __value) { 82 | _enabled = __value; 83 | redrawState(); 84 | } 85 | } 86 | 87 | public function get visibility():Number { 88 | return _visibility; 89 | } 90 | public function set visibility(__value:Number):void { 91 | if (_visibility != __value) { 92 | _visibility = __value; 93 | redrawVisibility(); 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /com/zehfernando/utils/tracking/ComscoreUtils.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.utils.tracking { 2 | 3 | import com.zehfernando.utils.console.log; 4 | 5 | import flash.display.Loader; 6 | import flash.display.LoaderInfo; 7 | import flash.events.Event; 8 | import flash.net.URLRequest; 9 | import flash.system.LoaderContext; 10 | 11 | /** 12 | * @author zeh 13 | */ 14 | public class ComscoreUtils { 15 | 16 | // ComScore tracking 17 | protected static var _verbose:Boolean; // If true, trace statements 18 | protected static var _simulated:Boolean; // If true, doesn't actually make any post 19 | 20 | // Properties 21 | protected static var loaders:Vector.; 22 | 23 | public function ComscoreUtils() { 24 | throw new Error("You cannot instantiate this class."); 25 | } 26 | 27 | // ================================================================================================================ 28 | // STATIC CONSTRUCTOR --------------------------------------------------------------------------------------------- 29 | 30 | { 31 | _verbose = true; 32 | _simulated = false; 33 | 34 | if (_verbose) log ("Initialized :: verbose set to ["+_verbose+"] and simulated set to ["+_simulated+"]"); 35 | 36 | loaders = new Vector.(); 37 | } 38 | 39 | // ================================================================================================================ 40 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 41 | 42 | protected static function onLoaderComplete(e:Event):void { 43 | // Loaded this loader, so remove from list 44 | var loaderIndex:int = loaders.indexOf(e.target); 45 | loaders[loaderIndex].removeEventListener(Event.COMPLETE, onLoaderComplete); 46 | loaders.splice(loaderIndex, 1); 47 | } 48 | 49 | // ================================================================================================================ 50 | // STATIC functions ----------------------------------------------------------------------------------------------- 51 | 52 | public static function trackURL(__url:String):void { 53 | if (_verbose) log ("[" + __url + "]"); 54 | if (!_simulated && Boolean(__url)) { 55 | var loader:Loader = new Loader(); 56 | loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete); 57 | loaders.push(loader.contentLoaderInfo); 58 | loader.load(new URLRequest(__url), new LoaderContext(true)); 59 | } 60 | } 61 | 62 | 63 | // ================================================================================================================ 64 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 65 | 66 | public static function get simulated():Boolean { 67 | return _simulated; 68 | } 69 | public static function set simulated(__value:Boolean):void { 70 | if (_simulated != __value) { 71 | _simulated = __value; 72 | log("simulated is " + _simulated); 73 | } 74 | } 75 | 76 | public static function get verbose():Boolean { 77 | return _verbose; 78 | } 79 | public static function set verbose(__value:Boolean):void { 80 | if (_verbose != __value) { 81 | _verbose = __value; 82 | log("verbose is " + _verbose); 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/youtube/services/YouTubeUserUploadsRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.youtube.services { 2 | import com.zehfernando.net.apis.BasicServiceRequest; 3 | import com.zehfernando.net.apis.youtube.YouTubeConstants; 4 | import com.zehfernando.net.apis.youtube.data.YouTubeVideo; 5 | import com.zehfernando.net.apis.youtube.events.YouTubeServiceEvent; 6 | 7 | import flash.events.Event; 8 | import flash.events.IOErrorEvent; 9 | import flash.events.SecurityErrorEvent; 10 | import flash.net.URLRequestMethod; 11 | 12 | /** 13 | * @author zeh 14 | */ 15 | public class YouTubeUserUploadsRequest extends BasicServiceRequest { 16 | 17 | // Properties 18 | protected var _userId:String; 19 | 20 | // Results 21 | protected var _videos:Vector.; 22 | 23 | // ================================================================================================================ 24 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 25 | 26 | public function YouTubeUserUploadsRequest() { 27 | super(); 28 | 29 | // Basic service configuration 30 | requestURL = YouTubeConstants.DOMAIN + YouTubeConstants.SERVICE_USER_UPLOADS; 31 | requestMethod = URLRequestMethod.GET; 32 | 33 | // Parameters 34 | // http://developers.facebook.com/docs/reference/api/page 35 | 36 | _userId = ""; 37 | 38 | 39 | } 40 | 41 | // ================================================================================================================ 42 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 43 | 44 | override protected function onSecurityError(e:SecurityErrorEvent):void { 45 | super.onSecurityError(e); 46 | dispatchEvent(new YouTubeServiceEvent(YouTubeServiceEvent.ERROR)); 47 | } 48 | 49 | override protected function onIOError(e:IOErrorEvent):void { 50 | super.onIOError(e); 51 | dispatchEvent(new YouTubeServiceEvent(YouTubeServiceEvent.ERROR)); 52 | } 53 | 54 | override protected function onComplete(e:Event):void { 55 | 56 | var vidData:XML = (new XML(loader.data)); 57 | 58 | /*FDT_IGNORE*/ 59 | var ns:Namespace = vidData.namespace(); 60 | default xml namespace = ns; 61 | /*FDT_IGNORE*/ 62 | 63 | _videos = YouTubeVideo.fromXMLList(vidData.child("entry")); 64 | 65 | default xml namespace = new Namespace(""); // WTF! one needs this otherwise the function below fails! 66 | 67 | super.onComplete(e); 68 | dispatchEvent(new YouTubeServiceEvent(YouTubeServiceEvent.COMPLETE)); 69 | } 70 | 71 | 72 | override public function execute():void { 73 | requestURL = requestURL.replace(YouTubeConstants.PARAMETER_USER_ID, _userId); 74 | super.execute(); 75 | } 76 | 77 | // ================================================================================================================ 78 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 79 | 80 | // Parameters 81 | 82 | public function get userId():String { 83 | return _userId; 84 | } 85 | public function set userId(__value:String):void { 86 | _userId = __value; 87 | } 88 | 89 | // Results 90 | 91 | public function get videos(): Vector. { 92 | return _videos.concat(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /com/zehfernando/display/progressbars/AbstractProgressBar.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.progressbars { 2 | import com.zehfernando.data.types.AutoAttenuatedNumber; 3 | 4 | import flash.display.Sprite; 5 | import flash.events.Event; 6 | 7 | /** 8 | * @author zeh 9 | */ 10 | public class AbstractProgressBar extends Sprite { 11 | 12 | /* 13 | A nice loader with value easing. 14 | */ 15 | 16 | // Properties 17 | protected var _value:AutoAttenuatedNumber; // Virtual amount 18 | 19 | 20 | // ================================================================================================================ 21 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 22 | 23 | public function AbstractProgressBar() { 24 | _value = new AutoAttenuatedNumber(8, 0, 0, true); 25 | 26 | addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); 27 | addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true); 28 | } 29 | 30 | 31 | // ================================================================================================================ 32 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 33 | 34 | protected function setAmount(__value:Number, __immediate:Boolean = false):void { 35 | if (isNaN(__value)) __value = 0; 36 | 37 | if (__immediate) { 38 | _value.target = _value.current = __value; 39 | if (Boolean(stage)) redrawAmount(); 40 | } else { 41 | _value.target = __value; 42 | } 43 | } 44 | 45 | protected function redrawAmount():void { 46 | // Redraws graphics to represent the correct amount 47 | throw new Error("AbstractLoader :: ERROR: redrawAmount() is not overridden!"); 48 | } 49 | 50 | 51 | // ================================================================================================================ 52 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 53 | 54 | protected function onAddedToStage(e:Event):void { 55 | _value.start(); 56 | addEventListener(Event.ENTER_FRAME, onEnterFrameDraw, false, 0, true); 57 | redrawAmount(); 58 | } 59 | 60 | protected function onRemovedFromStage(e:Event):void { 61 | _value.stop(); 62 | removeEventListener(Event.ENTER_FRAME, onEnterFrameDraw); 63 | } 64 | 65 | protected function onEnterFrameDraw(e:Event):void { 66 | redrawAmount(); 67 | } 68 | 69 | 70 | // ================================================================================================================ 71 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 72 | 73 | public function setAmountImmediately(__f:Number):void { 74 | setAmount(__f, true); 75 | } 76 | 77 | 78 | // ================================================================================================================ 79 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 80 | 81 | public function get amount():Number { 82 | return _value.target; 83 | } 84 | 85 | public function set amount(__value:Number):void { 86 | if (_value.target != __value) { 87 | setAmount(__value); 88 | } 89 | } 90 | 91 | public function get visibleAmount():Number { 92 | return _value.current; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookUserRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookUser; 4 | 5 | import flash.events.Event; 6 | import flash.net.URLRequestMethod; 7 | /** 8 | * @author zeh 9 | */ 10 | public class FacebookUserRequest extends BasicFacebookRequest { 11 | 12 | // http://developers.facebook.com/docs/reference/api/user 13 | // https://graph.facebook.com/711322444 14 | 15 | // Properties 16 | protected var _userId:String; 17 | 18 | // Parameters 19 | protected var _limit:int; 20 | 21 | // Results 22 | protected var _user:FacebookUser; 23 | 24 | // ================================================================================================================ 25 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 26 | 27 | public function FacebookUserRequest() { 28 | super(); 29 | 30 | // Basic service configuration 31 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_USER; 32 | requestMethod = URLRequestMethod.GET; 33 | 34 | // Parameters 35 | // http://developers.facebook.com/docs/reference/api/page 36 | 37 | _userId = ""; 38 | 39 | } 40 | 41 | // ================================================================================================================ 42 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 43 | 44 | // override protected function getURLVariables():URLVariables { 45 | // var vars:URLVariables = super.getURLVariables(); 46 | // 47 | // if (_limit > 0) vars["limit"] = _limit; 48 | // 49 | // return vars; 50 | // } 51 | 52 | // ================================================================================================================ 53 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 54 | 55 | override protected function onComplete(e:Event):void { 56 | var response:Object = JSON.parse(loader.data); 57 | 58 | _user = FacebookUser.fromJSONObject(response); 59 | 60 | super.onComplete(e); 61 | } 62 | 63 | // ================================================================================================================ 64 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 65 | 66 | override public function execute():void { 67 | 68 | // TODO: using the query parameter "ids" here instead of the normal url userId, one can get data for several users at the same time - redo this? 69 | // 'ids' also accept links! 70 | 71 | requestURL = requestURL.replace(FacebookConstants.PARAMETER_USER_ID, _userId); 72 | 73 | super.execute(); 74 | } 75 | 76 | // ================================================================================================================ 77 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 78 | 79 | // Parameters 80 | 81 | public function get userId():String { 82 | return _userId; 83 | } 84 | public function set userId(__value:String):void { 85 | _userId = __value; 86 | } 87 | 88 | // Results 89 | 90 | public function get user(): FacebookUser { 91 | return _user; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /com/zehfernando/display/templates/application/ApplicationFrame2Abstract.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.templates.application { 2 | 3 | import com.zehfernando.display.templates.application.events.ApplicationFrame2Event; 4 | import com.zehfernando.utils.RenderUtils; 5 | 6 | import flash.display.MovieClip; 7 | /** 8 | * @author Zeh 9 | */ 10 | public class ApplicationFrame2Abstract extends MovieClip { 11 | 12 | // Instances 13 | protected var _width:Number; 14 | protected var _height:Number; 15 | 16 | protected var inited:Boolean; 17 | protected var _initPhase:Number; 18 | 19 | public var userSpeedBytesPerSecond:Number; // Measured user speed 20 | public var userSpeedBitsPerSecond:Number; // Measured user speed 21 | public var userLoadingTime:Number; // Complete data loading time, in seconds 22 | 23 | // ================================================================================================================ 24 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 25 | 26 | public function ApplicationFrame2Abstract() { 27 | 28 | _width = 100; 29 | _height = 100; 30 | 31 | inited = false; 32 | _initPhase = 0; 33 | 34 | requestRedraw(); 35 | } 36 | 37 | 38 | // ================================================================================================================ 39 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 40 | 41 | public function init():void { 42 | // Start loading stuff 43 | inited = true; 44 | requestRedraw(); 45 | 46 | _initPhase = 1; 47 | dispatchEvent(new ApplicationFrame2Event(ApplicationFrame2Event.INIT_PROGRESS)); 48 | dispatchEvent(new ApplicationFrame2Event(ApplicationFrame2Event.INIT_COMPLETE)); 49 | } 50 | 51 | public function show():void { 52 | // Finished, shows itself 53 | } 54 | 55 | 56 | // ================================================================================================================ 57 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 58 | 59 | protected function requestRedraw():void { 60 | RenderUtils.addFunction(redrawWidth); 61 | RenderUtils.addFunction(redrawHeight); 62 | } 63 | 64 | protected function redrawWidth():void { 65 | // EXTEND THIS! 66 | } 67 | 68 | protected function redrawHeight():void { 69 | // EXTEND THIS! 70 | } 71 | 72 | 73 | // ================================================================================================================ 74 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 75 | 76 | override public function get width():Number { 77 | return _width; 78 | } 79 | override public function set width(__value:Number):void { 80 | if (_width != __value) { 81 | _width = __value; 82 | redrawWidth(); 83 | } 84 | } 85 | 86 | override public function get height():Number { 87 | return _height; 88 | } 89 | override public function set height(__value:Number):void { 90 | if (_height != __value) { 91 | _height = __value; 92 | redrawHeight(); 93 | } 94 | } 95 | 96 | public function getInitPhase():Number { 97 | return _initPhase; 98 | } 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookUsersRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookUser; 4 | 5 | import flash.events.Event; 6 | import flash.net.URLRequestMethod; 7 | import flash.net.URLVariables; 8 | /** 9 | * @author zeh 10 | */ 11 | public class FacebookUsersRequest extends BasicFacebookRequest { 12 | 13 | // Properties 14 | protected var _userIds:Vector.; 15 | 16 | // TODO: THIS IS NOT USED NOW 17 | 18 | // Parameters 19 | protected var _limit:int; 20 | 21 | // Results 22 | protected var _users:Vector.; 23 | 24 | // ================================================================================================================ 25 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 26 | 27 | public function FacebookUsersRequest() { 28 | super(); 29 | 30 | // Basic service configuration 31 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_USERS; 32 | requestMethod = URLRequestMethod.GET; 33 | 34 | // Parameters 35 | // http://developers.facebook.com/docs/reference/api/page 36 | 37 | _userIds = new Vector.(); 38 | 39 | } 40 | 41 | // ================================================================================================================ 42 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 43 | 44 | // override protected function getURLVariables():URLVariables { 45 | // var vars:URLVariables = super.getURLVariables(); 46 | // 47 | // if (_limit > 0) vars["limit"] = _limit; 48 | // 49 | // return vars; 50 | // } 51 | 52 | override protected function getData():Object { 53 | var vars:URLVariables = super.getData() as URLVariables; 54 | 55 | vars[FacebookConstants.PARAMETER_IDS_NAME] = _userIds.join(FacebookConstants.PARAMETER_LIST_SEPARATOR); 56 | 57 | return vars; 58 | } 59 | 60 | // ================================================================================================================ 61 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 62 | 63 | override protected function onComplete(e:Event):void { 64 | var response:Object = JSON.parse(loader.data); 65 | 66 | _users = FacebookUser.fromJSONObjectObject(response); 67 | 68 | super.onComplete(e); 69 | } 70 | 71 | // ================================================================================================================ 72 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 73 | 74 | override public function execute():void { 75 | super.execute(); 76 | } 77 | 78 | // ================================================================================================================ 79 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 80 | 81 | // Parameters 82 | 83 | public function get userIds(): Vector. { 84 | return _userIds; 85 | } 86 | public function set userIds(__value:Vector.):void { 87 | _userIds = __value; 88 | } 89 | 90 | // Results 91 | 92 | public function get users(): Vector. { 93 | return _users; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /com/zehfernando/display/shapes/BoxMarker.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.shapes { 2 | 3 | import com.zehfernando.data.types.Color; 4 | 5 | import flash.display.CapsStyle; 6 | import flash.display.JointStyle; 7 | import flash.display.LineScaleMode; 8 | import flash.display.Shape; 9 | import flash.display.Sprite; 10 | 11 | /** 12 | * @author zeh 13 | */ 14 | public class BoxMarker extends Sprite { 15 | 16 | // Properties 17 | protected var _lineColor:int; 18 | protected var _width:Number; 19 | protected var _height:Number; 20 | 21 | // Instances 22 | protected var background:Box; 23 | protected var foreground:Shape; 24 | 25 | // ================================================================================================================ 26 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 27 | 28 | public function BoxMarker(__width:Number = 100, __height:Number = 100, __lineColor:int = 0x555555, __backgroundColor:int = 0xe3e3e3) { 29 | _width = __width; 30 | _height = __height; 31 | 32 | background = new Box(100, 100, __backgroundColor); 33 | addChild(background); 34 | 35 | foreground = new Shape(); 36 | foreground.graphics.lineStyle(1.6, 0x000000, 1, false, LineScaleMode.NONE, CapsStyle.ROUND, JointStyle.MITER); 37 | foreground.graphics.drawRect(0, 0, 100, 100); 38 | foreground.graphics.moveTo(0, 0); 39 | foreground.graphics.lineTo(100, 100); 40 | foreground.graphics.moveTo(100, 0); 41 | foreground.graphics.lineTo(0, 100); 42 | foreground.graphics.endFill(); 43 | addChild(foreground); 44 | lineColor = __lineColor; 45 | 46 | redraw(); 47 | } 48 | 49 | 50 | // ================================================================================================================ 51 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 52 | 53 | protected function redraw():void { 54 | background.width = _width; 55 | background.height = _height; 56 | 57 | foreground.scaleX = _width/100; 58 | foreground.scaleY = _height/100; 59 | } 60 | 61 | 62 | // ================================================================================================================ 63 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 64 | 65 | public function get color():int { 66 | return background.color; 67 | } 68 | public function set color(__value:int):void { 69 | background.color = __value; 70 | } 71 | 72 | public function get lineColor():int { 73 | return _lineColor; 74 | } 75 | public function set lineColor(__value:int):void { 76 | if (_lineColor != __value) { 77 | _lineColor = __value; 78 | foreground.transform.colorTransform = Color.fromRRGGBB(_lineColor).toColorTransform(); 79 | } 80 | } 81 | 82 | // TODO: use invalidate 83 | 84 | override public function get width():Number { return _width; } 85 | override public function set width(__value:Number):void { 86 | if (_width != __value) { 87 | _width = __value; 88 | redraw(); 89 | } 90 | } 91 | 92 | override public function get height():Number { return _height; } 93 | override public function set height(__value:Number):void { 94 | if (_height != __value) { 95 | _height = __value; 96 | redraw(); 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /com/zehfernando/geom/AbstractCurve.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.geom { 2 | import flash.geom.Point; 3 | /** 4 | * @author zeh fernando 5 | */ 6 | public class AbstractCurve { 7 | 8 | // A base/abstract class for curves, useless by itself 9 | 10 | // Properties 11 | public var p1:Point; 12 | public var p2:Point; 13 | 14 | // ================================================================================================================ 15 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 16 | 17 | public function AbstractCurve(__p1:Point, __p2:Point) { 18 | p1 = __p1; 19 | p2 = __p2; 20 | } 21 | 22 | // ================================================================================================================ 23 | // PUBLIC functions ----------------------------------------------------------------------------------------------- 24 | 25 | public function getPointOnCurve(__t:Number):Point { 26 | return Point.interpolate(p2, p1, __t); 27 | } 28 | 29 | public function decompose(__maximumErrorDistanceAllowed:Number = 1, __maximumSegments:int = 100):Vector. { 30 | // Decomposes a curve into line segments, given a maximum allowed error distance 31 | var points:Vector. = new Vector.(); 32 | 33 | // Create items until the error drift is always smaller than the maximum allowed 34 | var i:int; 35 | var segments:int = 1; // Start with 1, which is quite possible if the curve is very straight 36 | var maxError:Number = NaN; 37 | var currentError:Number; 38 | var pCurve:Point; 39 | var pSegment:Point; 40 | while ((isNaN(maxError) || maxError > __maximumErrorDistanceAllowed) && segments < __maximumSegments) { 41 | maxError = 0; 42 | 43 | // Create all segments 44 | points.fixed = false; 45 | points.length = segments + 1; 46 | points.fixed = true; 47 | points[0] = p1; 48 | for (i = 1; i < segments; i++) { 49 | points[i] = getPointOnCurve(i/segments); 50 | } 51 | points[segments] = p2; 52 | 53 | // Verify error distance by checking the middle of every segment 54 | for (i = 0; i < points.length-1; i++) { 55 | pSegment = Point.interpolate(points[i], points[i+1], 0.5); 56 | pCurve = getPointOnCurve((i+0.5)/segments); 57 | currentError = Point.distance(pSegment, pCurve); 58 | if (currentError > maxError) { 59 | maxError = currentError; 60 | if (maxError > __maximumErrorDistanceAllowed) { 61 | // Off the maximum error distance already, no need to check further 62 | break; 63 | } 64 | } 65 | } 66 | 67 | segments++; 68 | } 69 | 70 | // Additional check to see if any of the other segments is removable 71 | // This is not strictly necessary but can happen for some curves 72 | for (i = 0; i < points.length-2; i++) { 73 | pSegment = Point.interpolate(points[i], points[i+2], 0.5); 74 | pCurve = getPointOnCurve((i+1)/segments); 75 | currentError = Point.distance(pSegment, pCurve); 76 | if (currentError < __maximumErrorDistanceAllowed) { 77 | // Can remove this point too 78 | points.splice(i+1, 1); 79 | i--; 80 | } 81 | } 82 | 83 | points.fixed = false; 84 | return points; 85 | } 86 | 87 | // ================================================================================================================ 88 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 89 | 90 | public function get length():Number { 91 | return Point.distance(p1, p2); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookFeedRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookFeedPost; 4 | 5 | import flash.events.Event; 6 | import flash.net.URLRequestMethod; 7 | import flash.net.URLVariables; 8 | 9 | /** 10 | * @author zeh 11 | */ 12 | public class FacebookFeedRequest extends BasicFacebookRequest { 13 | 14 | // By default, this gets the last 25 posts 15 | 16 | // Properties 17 | protected var _authorId:String; 18 | 19 | // Parameters 20 | protected var _limit:int; 21 | 22 | // Results 23 | protected var _posts:Vector.; 24 | 25 | // ================================================================================================================ 26 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 27 | 28 | public function FacebookFeedRequest() { 29 | super(); 30 | 31 | // Basic service configuration 32 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_FEED; 33 | requestMethod = URLRequestMethod.GET; 34 | 35 | // Parameters 36 | // http://developers.facebook.com/docs/reference/api/page 37 | 38 | _authorId = ""; 39 | 40 | } 41 | 42 | // ================================================================================================================ 43 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 44 | 45 | override protected function getData():Object { 46 | var vars:URLVariables = super.getData() as URLVariables; 47 | 48 | if (_limit > 0) vars["limit"] = _limit; 49 | 50 | return vars; 51 | } 52 | 53 | // ================================================================================================================ 54 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 55 | 56 | override protected function onComplete(e:Event):void { 57 | var response:Object = JSON.parse(loader.data); 58 | 59 | _posts = FacebookFeedPost.fromJSONObjectArray(response["data"]); 60 | 61 | super.onComplete(e); 62 | } 63 | 64 | // ================================================================================================================ 65 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 66 | 67 | override public function execute():void { 68 | requestURL = requestURL.replace(FacebookConstants.PARAMETER_AUTHOR_ID, _authorId); 69 | super.execute(); 70 | } 71 | 72 | // ================================================================================================================ 73 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 74 | 75 | // Parameters 76 | 77 | public function get authorId():String { 78 | return _authorId; 79 | } 80 | public function set authorId(__value:String):void { 81 | _authorId = __value; 82 | } 83 | 84 | // Hard parameters 85 | 86 | public function get limit():int { 87 | return _limit; 88 | } 89 | public function set limit(__value:int):void { 90 | if (_limit != __value) { 91 | _limit = __value; 92 | } 93 | } 94 | 95 | // Results 96 | 97 | public function get posts(): Vector. { 98 | return _posts.concat(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /com/zehfernando/display/containers/YouTubeImageContainer.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.containers { 2 | 3 | import com.zehfernando.net.apis.youtube.data.YouTubeVideo; 4 | import com.zehfernando.net.apis.youtube.events.YouTubeServiceEvent; 5 | import com.zehfernando.net.apis.youtube.services.YouTubeVideoInfoRequest; 6 | 7 | import flash.system.Security; 8 | 9 | /** 10 | * @author zeh at zehfernando.com 11 | */ 12 | public class YouTubeImageContainer extends ImageContainer { 13 | 14 | // Properties 15 | protected var _youTubeID:String; 16 | 17 | protected var _isGettingYouTubeInfo:Boolean; 18 | protected var videoInfo:YouTubeVideo; 19 | protected var videoInfoRequest:YouTubeVideoInfoRequest; 20 | 21 | // ================================================================================================================ 22 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 23 | 24 | public function YouTubeImageContainer(__width:Number = 100, __height:Number = 100, __color:Number = 0x000000) { 25 | super(__width, __height, __color); 26 | 27 | Security.loadPolicyFile("http://s.ytimg.com/"); 28 | Security.loadPolicyFile("http://i2.ytimg.com/crossdomain.xml"); 29 | Security.loadPolicyFile("http://i.ytimg.com/crossdomain.xml"); 30 | } 31 | 32 | // ================================================================================================================ 33 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 34 | 35 | protected function cancelGetYouTubeInfo():void { 36 | if (_isGettingYouTubeInfo) { 37 | videoInfoRequest.removeEventListener(YouTubeServiceEvent.COMPLETE, onLoadVideoInfoComplete); 38 | videoInfoRequest.removeEventListener(YouTubeServiceEvent.ERROR, onLoadVideoInfoError); 39 | videoInfoRequest.dispose(); 40 | videoInfoRequest = null; 41 | } 42 | } 43 | 44 | // ================================================================================================================ 45 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 46 | 47 | protected function onLoadVideoInfoComplete(e:YouTubeServiceEvent):void { 48 | videoInfo = (e.target as YouTubeVideoInfoRequest).video; 49 | 50 | cancelGetYouTubeInfo(); 51 | videoInfoRequest = null; 52 | 53 | super.load(videoInfo.thumbnails[2].url); 54 | //super.load(videoInfo.getHighestResolutionThumbnailURL()); 55 | } 56 | 57 | protected function onLoadVideoInfoError(e:YouTubeServiceEvent):void { 58 | cancelGetYouTubeInfo(); 59 | 60 | trace("YouTubeImageContainer :: Error when trying to load image info for " + _youTubeID); 61 | dispatchEvent(e); 62 | } 63 | 64 | // ================================================================================================================ 65 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 66 | 67 | override public function load(__id:String):void { 68 | cancelGetYouTubeInfo(); 69 | 70 | _youTubeID = __id; 71 | 72 | videoInfoRequest = new YouTubeVideoInfoRequest(); 73 | videoInfoRequest.videoId = _youTubeID; 74 | videoInfoRequest.addEventListener(YouTubeServiceEvent.COMPLETE, onLoadVideoInfoComplete); 75 | videoInfoRequest.addEventListener(YouTubeServiceEvent.ERROR, onLoadVideoInfoError); 76 | videoInfoRequest.execute(); 77 | } 78 | 79 | override public function dispose():void { 80 | cancelGetYouTubeInfo(); 81 | videoInfo = null; 82 | 83 | super.dispose(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /com/zehfernando/display/debug/QuickButton.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.debug { 2 | import com.zehfernando.display.shapes.RoundedBox; 3 | 4 | import flash.display.Sprite; 5 | import flash.events.MouseEvent; 6 | import flash.text.TextField; 7 | import flash.text.TextFormat; 8 | import flash.text.TextFormatAlign; 9 | 10 | /** 11 | * @author zeh 12 | */ 13 | public class QuickButton extends Sprite { 14 | 15 | // Properties 16 | protected var _width:Number; 17 | protected var _height:Number; 18 | protected var _text:String; 19 | 20 | // Instances 21 | protected var background:RoundedBox; 22 | protected var textField:TextField; 23 | 24 | // ================================================================================================================ 25 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 26 | 27 | public function QuickButton(__text:String = "CLICK", __x:Number = 0, __y:Number = 0, __onClick:Function = null, __width:Number = 70, __height:Number = 20) { 28 | x = __x; 29 | y = __y; 30 | _width = __width; 31 | _height = __height; 32 | _text = __text; 33 | 34 | background = new RoundedBox(100, 100, 0x3b856e, 4); 35 | background.superEllipseCorners = true; 36 | addChild(background); 37 | 38 | textField = new TextField(); 39 | textField.wordWrap = true; 40 | textField.selectable = false; 41 | textField.embedFonts = false; 42 | addChild(textField); 43 | 44 | var fmt:TextFormat = new TextFormat(); 45 | fmt.font = "_sans"; 46 | fmt.bold = true; 47 | fmt.size = 12; 48 | fmt.color = 0xffffff; 49 | fmt.align = TextFormatAlign.CENTER; 50 | textField.defaultTextFormat = fmt; 51 | 52 | buttonMode = true; 53 | mouseChildren = false; 54 | 55 | if (Boolean(__onClick)) addEventListener(MouseEvent.CLICK, __onClick); 56 | 57 | redraw(); 58 | } 59 | 60 | 61 | // ================================================================================================================ 62 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 63 | 64 | public function redraw():void { 65 | background.width = _width; 66 | background.height = _height; 67 | 68 | textField.text = _text; 69 | textField.x = 0; 70 | textField.width = _width; 71 | textField.height = textField.textHeight + 4; 72 | textField.y = _height / 2 - textField.height / 2; 73 | } 74 | 75 | 76 | // ================================================================================================================ 77 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 78 | 79 | // TODO: use invalidate 80 | // The repetitive redraws don't look good but impact in rendering is virtually none 81 | 82 | override public function get width():Number { return _width; } 83 | override public function set width(__value:Number):void { 84 | if (_width != __value) { 85 | _width = __value; 86 | redraw(); 87 | } 88 | } 89 | 90 | override public function get height():Number { return _height; } 91 | override public function set height(__value:Number):void { 92 | if (_height != __value) { 93 | _height = __value; 94 | redraw(); 95 | } 96 | } 97 | 98 | public function get text():String { return _text; } 99 | public function set text(__value:String):void { 100 | if (_text != __value) { 101 | _text = __value; 102 | redraw(); 103 | } 104 | } 105 | 106 | 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /com/zehfernando/display/shapes/Box.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.display.shapes { 2 | import flash.display.Sprite; 3 | 4 | /** 5 | * @author Zeh Fernando 6 | */ 7 | public class Box extends Sprite { 8 | 9 | // Properties 10 | protected var _width:Number; 11 | protected var _height:Number; 12 | protected var _color:uint; 13 | 14 | protected var _outlineWidth:Number; 15 | 16 | // ================================================================================================================ 17 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 18 | 19 | public function Box(__width:Number = 100, __height:Number = 100, __color:int = -1, __outlineWidth:Number = 0) { 20 | 21 | _width = __width; 22 | _height = __height; 23 | _color = (__color < 0 ? Math.random() * 0xffffff : __color) & 0xffffff; 24 | 25 | _outlineWidth = __outlineWidth; 26 | 27 | paint(); 28 | } 29 | 30 | 31 | // ================================================================================================================ 32 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 33 | 34 | protected function paint():void { 35 | graphics.clear(); 36 | graphics.lineStyle(); 37 | graphics.beginFill(_color); 38 | graphics.drawRect(0, 0, _width, _height); 39 | 40 | if (_outlineWidth != 0) graphics.drawRect(_outlineWidth, _outlineWidth, _width - _outlineWidth * 2, _height - _outlineWidth * 2); 41 | 42 | graphics.endFill(); 43 | } 44 | 45 | 46 | // ================================================================================================================ 47 | // ACCESSOR functions --------------------------------------------------------------------------------------------- 48 | 49 | public function get color():uint { return _color; } 50 | public function set color(__value:uint):void { 51 | if (_color != __value) { 52 | _color = __value & 0xffffff; 53 | paint(); 54 | } 55 | } 56 | 57 | public function get colorR():Number { return ((_color & 0xff0000) >> 16)/255; } 58 | public function set colorR(__value:Number):void { 59 | _color = (_color & 0x00ffff) | (Math.round(__value * 255) << 16); 60 | paint(); 61 | } 62 | 63 | public function get colorG():Number { return ((_color & 0xff00) >> 8)/255; } 64 | public function set colorG(__value:Number):void { 65 | _color = (_color & 0xff00ff) | (Math.round(__value * 255) << 8); 66 | paint(); 67 | } 68 | 69 | public function get colorB():Number { return (_color & 0xff) / 255; } 70 | public function set colorB(__value:Number):void { 71 | _color = (_color & 0xffff00) | Math.round(__value * 255); 72 | paint(); 73 | } 74 | 75 | override public function get width():Number { return _width; } 76 | override public function set width(__value:Number):void { 77 | if (isNaN(__value)) __value = 0; 78 | if (_width != __value) { 79 | _width = __value; 80 | paint(); 81 | } 82 | } 83 | 84 | override public function get height():Number { return _height; } 85 | override public function set height(__value:Number):void { 86 | if (isNaN(__value)) __value = 0; 87 | if (_height != __value) { 88 | _height = __value; 89 | paint(); 90 | } 91 | } 92 | 93 | public function get outlineWidth():Number { return _outlineWidth; } 94 | public function set outlineWidth(__value:Number):void { 95 | if (isNaN(__value)) __value = 0; 96 | if (_outlineWidth != __value) { 97 | _outlineWidth = __value; 98 | paint(); 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookPostsRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookFeedPost; 4 | 5 | import flash.events.Event; 6 | import flash.net.URLRequestMethod; 7 | import flash.net.URLVariables; 8 | /** 9 | * @author zeh at zehfernando.com 10 | */ 11 | public class FacebookPostsRequest extends BasicFacebookRequest { 12 | 13 | // By default, this gets the last 25 posts 14 | // TODO: join this with the FacebookFeedRequest service, but using something like .ownAuthor? 15 | 16 | // Properties 17 | protected var _authorId:String; 18 | 19 | // Parameters 20 | protected var _limit:int; 21 | 22 | // Results 23 | protected var _posts:Vector.; 24 | 25 | // ================================================================================================================ 26 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 27 | 28 | public function FacebookPostsRequest() { 29 | super(); 30 | 31 | // Basic service configuration 32 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_POSTS; 33 | requestMethod = URLRequestMethod.GET; 34 | 35 | // Parameters 36 | // http://developers.facebook.com/docs/reference/api/page 37 | 38 | _authorId = ""; 39 | 40 | } 41 | 42 | // ================================================================================================================ 43 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 44 | 45 | override protected function getData():Object { 46 | var vars:URLVariables = super.getData() as URLVariables; 47 | 48 | if (_limit > 0) vars["limit"] = _limit; 49 | 50 | return vars; 51 | } 52 | 53 | // ================================================================================================================ 54 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 55 | 56 | override protected function onComplete(e:Event):void { 57 | var response:Object = JSON.parse(loader.data); 58 | 59 | _posts = FacebookFeedPost.fromJSONObjectArray(response["data"]); 60 | 61 | super.onComplete(e); 62 | } 63 | 64 | // ================================================================================================================ 65 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 66 | 67 | override public function execute():void { 68 | requestURL = requestURL.replace(FacebookConstants.PARAMETER_AUTHOR_ID, _authorId); 69 | super.execute(); 70 | } 71 | 72 | // ================================================================================================================ 73 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 74 | 75 | // Parameters 76 | 77 | public function get authorId():String { 78 | return _authorId; 79 | } 80 | public function set authorId(__value:String):void { 81 | _authorId = __value; 82 | } 83 | 84 | // Hard parameters 85 | 86 | public function get limit():int { 87 | return _limit; 88 | } 89 | public function set limit(__value:int):void { 90 | if (_limit != __value) { 91 | _limit = __value; 92 | } 93 | } 94 | 95 | // Results 96 | 97 | public function get posts(): Vector. { 98 | return _posts.concat(); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookAlbumsRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookAlbum; 4 | 5 | import flash.events.Event; 6 | import flash.net.URLRequestMethod; 7 | import flash.net.URLVariables; 8 | 9 | /** 10 | * @author zeh 11 | */ 12 | public class FacebookAlbumsRequest extends BasicFacebookRequest { 13 | 14 | // http://developers.facebook.com/docs/reference/api/photo 15 | // http://developers.facebook.com/docs/reference/api/album 16 | // https://graph.facebook.com/rmstitanicinc/albums 17 | 18 | // Properties 19 | protected var _authorId:String; 20 | 21 | // Parameters 22 | protected var _limit:int; 23 | 24 | // Results 25 | protected var _albums:Vector.; 26 | 27 | // ================================================================================================================ 28 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 29 | 30 | public function FacebookAlbumsRequest() { 31 | super(); 32 | 33 | // Basic service configuration 34 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_ALBUMS; 35 | requestMethod = URLRequestMethod.GET; 36 | 37 | // Parameters 38 | // http://developers.facebook.com/docs/reference/api/page 39 | 40 | _authorId = ""; 41 | 42 | } 43 | 44 | // ================================================================================================================ 45 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 46 | 47 | override protected function getData():Object { 48 | var vars:URLVariables = super.getData() as URLVariables; 49 | 50 | if (_limit > 0) vars["limit"] = _limit; 51 | 52 | return vars; 53 | } 54 | 55 | // ================================================================================================================ 56 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 57 | 58 | override protected function onComplete(e:Event):void { 59 | var response:Object = JSON.parse(loader.data); 60 | 61 | _albums = FacebookAlbum.fromJSONObjectArray(response["data"]); 62 | 63 | super.onComplete(e); 64 | } 65 | 66 | // ================================================================================================================ 67 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 68 | 69 | override public function execute():void { 70 | requestURL = requestURL.replace(FacebookConstants.PARAMETER_AUTHOR_ID, _authorId); 71 | super.execute(); 72 | } 73 | 74 | // ================================================================================================================ 75 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 76 | 77 | // Parameters 78 | 79 | public function get authorId():String { 80 | return _authorId; 81 | } 82 | public function set authorId(__value:String):void { 83 | _authorId = __value; 84 | } 85 | 86 | // Hard parameters 87 | 88 | public function get limit():int { 89 | return _limit; 90 | } 91 | public function set limit(__value:int):void { 92 | if (_limit != __value) { 93 | _limit = __value; 94 | } 95 | } 96 | 97 | // Results 98 | 99 | public function get albums(): Vector. { 100 | return _albums.concat(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /com/zehfernando/net/apis/facebook/services/FacebookAlbumPhotosRequest.as: -------------------------------------------------------------------------------- 1 | package com.zehfernando.net.apis.facebook.services { 2 | import com.zehfernando.net.apis.facebook.FacebookConstants; 3 | import com.zehfernando.net.apis.facebook.data.FacebookPhoto; 4 | 5 | import flash.events.Event; 6 | import flash.net.URLRequestMethod; 7 | import flash.net.URLVariables; 8 | 9 | /** 10 | * @author zeh 11 | */ 12 | public class FacebookAlbumPhotosRequest extends BasicFacebookRequest { 13 | 14 | // http://developers.facebook.com/docs/reference/api/photo 15 | // http://developers.facebook.com/docs/reference/api/album 16 | 17 | // https://graph.facebook.com/143423629024057/photos 18 | 19 | // Properties 20 | protected var _albumId:String; 21 | 22 | // Parameters 23 | protected var _limit:int; 24 | 25 | // Results 26 | protected var _photos:Vector.; 27 | 28 | // ================================================================================================================ 29 | // CONSTRUCTOR ---------------------------------------------------------------------------------------------------- 30 | 31 | public function FacebookAlbumPhotosRequest() { 32 | super(); 33 | 34 | // Basic service configuration 35 | requestURL = FacebookConstants.SERVICE_DOMAIN + FacebookConstants.SERVICE_ALBUM_PHOTOS; 36 | requestMethod = URLRequestMethod.GET; 37 | 38 | // Parameters 39 | // http://developers.facebook.com/docs/reference/api/page 40 | 41 | _albumId = ""; 42 | 43 | } 44 | 45 | // ================================================================================================================ 46 | // INTERNAL INTERFACE --------------------------------------------------------------------------------------------- 47 | 48 | override protected function getData():Object { 49 | var vars:URLVariables = super.getData() as URLVariables; 50 | 51 | if (_limit > 0) vars["limit"] = _limit; 52 | 53 | return vars; 54 | } 55 | 56 | // ================================================================================================================ 57 | // EVENT INTERFACE ------------------------------------------------------------------------------------------------ 58 | 59 | override protected function onComplete(e:Event):void { 60 | var response:Object = JSON.parse(loader.data); 61 | 62 | _photos = FacebookPhoto.fromJSONObjectArray(response["data"]); 63 | 64 | super.onComplete(e); 65 | } 66 | 67 | // ================================================================================================================ 68 | // PUBLIC INTERFACE ----------------------------------------------------------------------------------------------- 69 | 70 | override public function execute():void { 71 | requestURL = requestURL.replace(FacebookConstants.PARAMETER_ALBUM_ID, _albumId); 72 | super.execute(); 73 | } 74 | 75 | // ================================================================================================================ 76 | // ACCESSOR INTERFACE --------------------------------------------------------------------------------------------- 77 | 78 | // Parameters 79 | 80 | public function get albumId():String { 81 | return _albumId; 82 | } 83 | public function set albumId(__value:String):void { 84 | _albumId = __value; 85 | } 86 | 87 | // Hard parameters 88 | 89 | public function get limit():int { 90 | return _limit; 91 | } 92 | public function set limit(__value:int):void { 93 | if (_limit != __value) { 94 | _limit = __value; 95 | } 96 | } 97 | 98 | // Results 99 | 100 | public function get photos(): Vector. { 101 | return _photos.concat(); 102 | } 103 | } 104 | } 105 | --------------------------------------------------------------------------------