Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slai committed Jun 28, 2009
0 parents commit 91c892d
Show file tree
Hide file tree
Showing 30 changed files with 2,400 additions and 0 deletions.
29 changes: 29 additions & 0 deletions common/com/chumby/util/Delegate.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Delegate class - allows additional parameters when creating the Delegate
* see flashdevelop.org for more info and discussion
*/

class com.chumby.util.Delegate
{
/**
* Create a delegate function
* @param target Objet context
* @param handler Method to call
*/
public static function create(target:Object, handler:Function):Function
{
var func = function()
{
var context:Function = arguments.callee;
var args:Array = arguments.concat(context.initArgs);
return context.handler.apply(context.target, args);
}

// Don't use local references to avoid "Persistent activation object" bug
// See: http://timotheegroleau.com/Flash/articles/scope_chain.htm
func.target = target;
func.handler = handler;
func.initArgs = arguments.slice(2);
return func;
}
}
39 changes: 39 additions & 0 deletions common/com/chumby/util/MCUtil.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* functions for associating movieclips with classes
* see flashdevelop.org for more info
*/

class com.chumby.util.MCUtil
{
//create a movieClip and associate a class with it
//Sam: added constructorArgs
static public function CreateWithClass( classRef:Function,target:MovieClip, name:String, depth:Number, params:Object, constructorArgs:Array )
{
var mc:MovieClip=target.createEmptyMovieClip(name,depth);
mc.__proto__ = classRef.prototype;
if (params != null) for (var i in params) mc[i] = params[i];
if (constructorArgs == undefined)
classRef.apply(mc);
else
classRef.apply(mc, constructorArgs);
return mc;
}

//attach a movieClip from the library and associate a class with it
static public function AttachWithClass( classRef:Function, target:MovieClip, id:String, name:String, depth:Number, params:Object )
{
var mc:MovieClip = target.attachMovie(id, name, depth, params);
mc.__proto__ = classRef.prototype;
classRef.apply(mc);
return mc;
}

//link a class with an existing movieClip, use for _root / timeline association
static public function LinkWithClass( classRef:Function, target:MovieClip )
{
var mc:MovieClip = target;
mc.__proto__ = classRef.prototype;
classRef.apply(mc);
return target;
}
}
100 changes: 100 additions & 0 deletions common/com/chumby/util/xml/XmlUtil.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Copyright (c) 2008 Chumby Industries
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Useful XML functions
*/

class com.chumby.util.xml.XmlUtil
{
public static function childrenOfType(x:XMLNode, s:String) :Array
{
var a:Array = new Array();
var n:XMLNode = x.firstChild;
while (n) {
if (n.nodeName==s) {
a.push(n);
}
n = n.nextSibling;
}
return a;
}

public static function childrenThat(x:XMLNode, f:Function) :Array
{
var a:Array = new Array();
var n:XMLNode = x.firstChild;
while (n) {
if (f(n)) {
a.push(n);
}
n = n.nextSibling;
}
return a;
}

public static function firstChildOfType(x:XMLNode, s:String) :XMLNode
{
//trace("firstChildOfType: " + s);
var n:XMLNode = x.firstChild;
while (n) {
//trace(n.nodeName);
if (n.nodeName==s) {
//trace("---");
return n;
}
n = n.nextSibling;
}
return null;
}

public static function firstChildThat(x:XMLNode, f:Function) :XMLNode
{
var n:XMLNode = x.firstChild;
while (n) {
if (f(n)) {
return n;
}
n = n.nextSibling;
}
return null;
}

public static function firstDescendantOfType(x:XMLNode, s:String) :XMLNode
{
var n:XMLNode = firstChildOfType(x,s);
if (n) return n;
n = x.firstChild;
while (n) {
var k:XMLNode = firstDescendantOfType(n, s);
if (k) return k;
n = n.nextSibling;
}
return null;
}

// returns the text of first child item of an element with the given tag
public static function firstValueOfType(x:XMLNode, s:String) :String
{
var n:XMLNode = x.firstChild;
while (n) {
if (n.nodeName==s) {
return n.firstChild.nodeValue;
}
n = n.nextSibling;
}
return null;
}
}
41 changes: 41 additions & 0 deletions common/netusage/INetUsageData.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Interface for getting net usage data. To be implemented in each version (ISP).
*
* @author Samuel Lai
*/
interface netusage.INetUsageData
{
function init():Void;

function start():Void;
function hasStarted():Boolean;

//loads logo into target, returning itself
function loadLogo(target:MovieClip, instanceName:String, depth:Number):MovieClip;

function getLastUpdated():Date;
function setOnUpdated(f:Function):Void;
function setOnError(f:Function):Void; //has a String parameter with error message.

function getAccountName():String;

function getRolloverDate():Date;

function hasOffPeak():Boolean;
//returns true if currently in peak period. If no off-peak period, return true always.
function isPeak():Boolean;

//in MB
function getPeakDataUsed():Number;
//in MB
function getPeakDataQuota():Number;
//in cents
function getPeakExcessCost():Number;

//in MB
function getOffPeakDataUsed():Number;
//in MB
function getOffPeakDataQuota():Number;
//in cents
function getOffPeakExcessCost():Number;
}
Loading

0 comments on commit 91c892d

Please sign in to comment.