Credit where credit is due, originally found here:
http://www.rblab.com/blog/2009/07/as3-snippet-convert-seconds-to-wwddhhmmss/

function convertTime(number:Number):String
{
number = Math.abs(number);
var values:Array = new Array(5);
values[0] = Math.floor(number / 86400 / 7);// weeks
values[1] = Math.floor(number / 86400 % 7);// days
values[2] = Math.floor(number / 3600 % 24);// hours
values[3] = Math.floor(number / 60 % 60);// mins
values[4] = Math.floor(number % 60);// secs

var stopage:Boolean = false;
var cutIndex:Number = -1;

for (var i:Number = 0; i < values.length; i++)
{
if (values[i] < 10)
{
values[i] = "0" + values[i];
}
if (values[i] == "00" && i < (values.length - 2) && !stopage)
{
cutIndex = i;
}
else
{
stopage = true;
}
}
values.splice(0, cutIndex + 1);

return values.join(":");
}

public class Main extends Sprite {

private static var _instance:Main;
public static function get instance():Main { return _instance; }

public function Main() {
_instance = this;
// etc...
}

// etc...
}

Then you access the Main instance like this:

public class Other {
public function Other() {
Main.instance.usefulInstanceMethod();
}
}

original source:

http://stackoverflow.com/questions/370222/accessing-the-document-class-in-as3

JAVASCRIPT DEPENDENT!


var currentURL = ExternalInterface.call('window.location.href.toString');
var isEnglishPage:RegExp = /somethingenglish/i;

function mc_someButton_CLICK(e:MouseEvent):void {

if (isEnglishPage.test( currentURL )) {
navigateToURL(new URLRequest("/eng/some.html"), "_parent");
} else {
navigateToURL(new URLRequest("/span/some.html"), "_parent");
}

}

if (Boolean(this.getChildByName('primary_content'))) {

// yeah it exists do something here

}


function trim(s:String):String {
return s ? s.replace(/^\s+|\s+$/gs, '') : "";
}


butt_shareThis.addEventListener(MouseEvent.CLICK, butt_shareThis_CLICK);
function butt_shareThis_CLICK(e:MouseEvent):void {

// this line sends it to the standard alert box
navigateToURL(new URLRequest("javascript:alert('SHARE THIS Test');"), "_self");

// this line sends it console.log
navigateToURL(new URLRequest("javascript:console.log('SHARE THIS Test to console.log');"), "_self");

}

Mar 152010

// new Timer([interval], [repeat]);
var myTimer:Timer = new Timer(2000, 1);
myTimer.addEventListener(TimerEvent.TIMER, addDriverGrid);

myTimer.start();

function addDriverGrid(event:TimerEvent):void {
trace(“addDriverGrid()”);
}

label_txt.autoSize = TextFieldAutoSize.NONE — The default. No resizing.

label_txt.autoSize = TextFieldAutoSize.LEFT — Will automatically resize the textfield and left-align the text.

label_txt.autoSize = TextFieldAutoSize.CENTER — Will automatically resize the textfield and center the text.

label_txt.autoSize = TextFieldAutoSize.RIGHT — Will automatically resize the textfield and right-align the text.

Tween out the volume of a netStream object:

Tweens the volume down to 0 over 1 second
var sndTransform = new SoundTransform();
nsStream.soundTransform = sndTransform;
TweenMax.to( nsStream, 1, { volume:0 });

needs TweenMax classes imported:

import com.greensock.*;
import com.greensock.easing.*;


import fl.motion.Color;

var rmColorTransform:Color;
var bgColorTransform:Color;

function highlight_pad(mc):void {

bgColorTransform = new Color();
bgColorTransform.setTint(0x666666, 1); //alpha is second parameter
mc.transform.colorTransform = bgColorTransform;

}

function clear_pad(mc):void {

rmColorTransform = new Color();
rmColorTransform.setTint(0xFF0000 , 0); //alpha is second parameter
mc.transform.colorTransform = rmColorTransform;

}

© 2012 James Border Suffusion theme by Sayontan Sinha