Skip to content

Instantly share code, notes, and snippets.

@troygilbert
troygilbert / Application.as
Created April 2, 2010 21:59
Preloader Demo
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Application extends Sprite
{
/** Constructor. **/
public function Application()
{
@troygilbert
troygilbert / Preloader.as
Created April 3, 2010 04:38
Preloader.as
package
{
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.ProgressEvent;
@troygilbert
troygilbert / MyAppPreloader.as
Created April 3, 2010 04:58
MyAppPreloader.as
package
{
import flash.display.Graphics;
import flash.display.TextField;
public class MyAppPreloader extends Preloader
{
/** Text display of progress. **/
protected var tf:TextField;
@troygilbert
troygilbert / InvalidationPattern.as
Created April 8, 2010 04:46
Invalidate Pattern example
package
{
import flash.display.Shape;
import flash.events.Event;
public class InvalidationPattern
{
protected const USE_DEFERRED_VALIDATION:Boolean = true;
protected var tickerShape:Shape;
@troygilbert
troygilbert / AutoSizedWindow.as
Created April 15, 2010 04:25
AutoSizedWindow
package
{
import flash.display.NativeWindow;
import flash.geom.Point;
import mx.core.ScrollPolicy;
import mx.core.Window;
public class AutoSizedWindow extends Window
{
@troygilbert
troygilbert / ResourceLibrary.xml
Created April 18, 2010 16:44
ResourceLibrary.mxml
<!-- The root of the XML needs to support namespaces that map to packages. -->
<mb:ResourceLibrary
xmlns:mb="com.mockingbirdgames.document.*"
xmlns:tweaks="com.mockingbirdgames.document.tweaks.*"
xmlns:behaviors="com.playmockingbird.behaviors.*"
>
<!-- We use shorthand for setting the contents of a child element. -->
<!-- Instead of: <mb:SpriteCollection id="sprites"/> -->
<mb:sprites>
@troygilbert
troygilbert / CharacterEquipsItem.as
Created April 29, 2010 20:47
Character Equips Item
/** This base class works for both players and enemies, as far as items are concerned. **/
public class Character
{
/** This is a list of items equiped on the character. **/
public var equipedItems:Array = [ ];
/** Equips an item on the character, unequiping it from its current owner. **/
public function equip(item:Item):void
{
if (item.owner) item.owner.unequip(item); // unequip item from its current owner
@troygilbert
troygilbert / MyCustomControl.as
Created May 12, 2010 04:51
Throws null ref exception
package
{
public class MyCustomControl
{
protected var someDependency:Object;
[Bindable]
public function get someProperty():Object { return null; }
public function set someProperty(value:Object):void
{
@troygilbert
troygilbert / ClassWithPrivateInjection.as
Created September 23, 2010 04:00
Demonstrate private injection for DI
package
{
import private_injection;
class ClassWithPrivateInjection
{
include "inject.include.as";
private var mySecretWord:String;
@troygilbert
troygilbert / e4xbug.as
Created January 20, 2011 22:16
Weird bug with E4X syntax
var xml:XML = <root><child name="one"/></root>;
var name:String = "one";
var matches:XMLList = xml.child.(@name == name);
trace(matches.length()); // 0
var nameValue:String = name;
matches = xml.child.(@name == nameValue);
trace(matches.length()); // 1