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");

}

AS3 Timer

Mar, 15 -- Categories: Actionscript

// 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()”);
}

AS-3 TextFieldAutoSize

Feb, 10 -- Categories: Actionscript

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.

AS3 Manipulating volume

Dec, 14 -- Categories: Actionscript

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;

}

AS3 Smooth Loaded Bitmaps

Oct, 29 -- Categories: Actionscript

//create a new loader object and put it on the stage
var slideLoader:Loader=new Loader();
this.addChild(slideLoader);

//load picture into loader object
slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, scaleContentForPicture);
slideLoader.load(new URLRequest(“images/tree.jpg”));

//smooth it once loaded
function scaleContentForPicture() {
var smoother_bm=Bitmap(slideLoader.content);
smoother_bm.smoothing=true;
}

After using swfobject I thought I’d never have to pass variables to a swf thru the query string again…. oops.
Wrong…. and I had to look it up. I’m using a lightbox for a flv player and right now it looks like the easy way to make it happen is like this:

here is the lightbox call (the only relevant part of this is the ?recordID=2)

<a rel=“prettyPhoto[philosophy]” title=“Vid1” href=”/flash/XXXXXX.swf?recordID=2” rel=“prettyPhoto[philosophy]” title=“Description”></a>

here is the actionscript that gets it then assigns the piece I want:

var queryString = this.loaderInfo.parameters;
var whichVideo =  queryString.recordID;

The class object adds an mouse event listener, that object is added to the stage five times and waits to get clicked
custom_class.zip

//The number after the asterisk is the range from which the random number will come
//A random number between 1 and 100, since i’m using an int there will be no .whatever
var randomNumber:int = Math.random()*100;
trace(randomNumber);

/// with a range and I’m told with a better value distribution

var lowVal:int = 100;
var highVal:int = 201;

var randomNumber:int = ( Math.random() * (1+highVal-lowVal) ) + lowVal;

trace(randomNumber);

// import the class
import fl.data.DataProvider;

// create and load some data into the comboBox
// this one is already on the stage but you can also var myCBox:ComboBox = new ComboBox(); etc.
var dp:DataProvider = new DataProvider();
var sortFilters:Array = [ ["value 1", "Label 1"], ["value 2", "Label 2"], ["value 3", "Label 3"], ["value 4", "Label 4"],];

for (var i:uint=0; i < sortFilters.length; i++) {
dp.addItem( { label: sortFilters[i][1], data:sortFilters[i][0] } );
}

myCBox.dataProvider = dp;

// add the listener
myCBox.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void {
whateverYouWantToHappen();
}

Video codecs such as On2 VP6 and Sorenson Spark perform better when the frame width and height use multiples of 16. While you can use any width and height in your encoding settings, non-optimal dimensions can result in poor image quality and reduced frame rate. For the best image quality and playback, you should always use width and height dimensions that use a multiple of 4 (good), 8 (better), or 16 (best). Refer to the following tables to pick dimensions for your layout.
NOTE: Both the native encoding dimensions and the playback dimensions should be a multiple of 16. For example, if you encode your FLV file to use a frame dimension of 320×240, you should scale to a size such as 512×384.
Table 1 - 4:3 Aspect Ratio Sizes

Best (16)
Better (8)

Good (4)

640 x 480
608 x 456
624 x 468

576 x 432
544 x 408
592 x 444

512 x 384
480 x 360
560 x 420

448 x 336
416 x 312
528 x 396

384 x 288
352 x 264
496 x 372

320 x 240
288 x 216
464 x 348

256 x 192
224 x 168
432 x 324

192 x 144
160 x 120
400 x 300

128 x 96

 
368 x 276

 
 
336 x 252

 
 
304 x 228

 
 
272 x 204

 
 
240 x 180

 
 
208 x 156

 

 
176 x 132

 
 
144 x 108

 
 
112 x 84

Table 2 - 16:9 Aspect Ratio Sizes

Best (16)
Better (8)
Good (4)

1280 x 720
1152 x 648

1216 x 684

1024 x 576
896 x 504
1088 x 612

768 x 432
640 x 360
960 x 540

512 x 288
384 x 216
832 x 468

256 x 144
128 x 72
704 x 396

 
 
576 x 324

 
 
448 x 252

 
 
320 x 180

 
 
192 x 108

The XML

<data>

<button handle=”prim_butt1″ text=”Larry” x=”60″ y=”160″ ></button>

<button handle=”prim_butt2″ text=”Moe” x=”170″ y=”160″ ></button>

<button handle=”prim_butt3″ text=”Curly” x=”280″ y=”160″ ></button>

<button handle=”prim_butt4″ text=”Shemp” x=”390″ y=”160″ ></button>

</data>

Now The Actionscript:

package {

import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;

import mc_button_primary;

public class StarterClass extends MovieClip {

private var i:Number;
private var primButtonCount:Number;
private var xmlLoader:URLLoader;
private var dataXML:XML;
private var buttonPrimary:mc_button_primary;
private var urlArray = new Array();

public function StarterClass() {

trace(“StarterClass……….√ check”);

// create a loader for our xml file
xmlLoader = new URLLoader(new URLRequest(“nav_primary.xml”));
// oops couldn't get our xml file
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, noFile);
// got our file now go do something (myInitMethod) with it
xmlLoader.addEventListener(Event.COMPLETE, myInitMethod);

// THROW ERROR IF XML SHOOTS CRAPS
function noFile(evt:IOErrorEvent):void {
trace(“Error. Data file not found.”);
}

}

// and now to do something with our data
private function myInitMethod(evt:Event):void {

trace(“myInitMethod……….√ check”);

// make sure flash knows it xml
dataXML = XML(xmlLoader.data);

// number of buttons in our xml
primButtonCount = dataXML.button.length();

// loop thru each button and make the data useful
for (i=0; i< primButtonCount; i++) {

trace("foo > “+dataXML.button[i].@handle );

// this is an array that contains the button text and it looks like
// urlArray[”prim_butt1″] == “Larry”

// it's referenced it in the click event
urlArray[dataXML.button[i].@handle] = dataXML.button[i].@text;

// create a new button from the library object
buttonPrimary = new mc_button_primary();
// give it a name
buttonPrimary.name = dataXML.button[i].@handle.toString();
// put it on the stage
addChild( buttonPrimary );

// find our new named button and give it a handle
var bttn_handle = getChildByName( buttonPrimary.name );
// now use the handle to move it and add text
bttn_handle.x = dataXML.button[i].@x;
bttn_handle.y = dataXML.button[i].@y;
bttn_handle.button_Text.text = dataXML.button[i].@text;
// add a listener so you can do something when you click it
bttn_handle.addEventListener( MouseEvent.CLICK, myButton_CLICK );

}

}

// here is the click event
function myButton_CLICK(event:MouseEvent):void {

// the name comes fom the urlArray ceated above
trace( “The button clicked was > “+urlArray[ event.target.name ]);

}

}

}
StarterClass_xml_basic.zip

// for this example I just want to count down 30 Seconds
var remainingSeconds:int = 30;

// this is the function that the setInterval function calls
function countDownSeconds() {

// not a second off of the current number of seconds
remainingSeconds--;

// if we have run out of seconds do this
if (remainingSeconds == 0) {

trace(“DONE”);
clearInterval(myInterval);

} else {

trace(“tic”);

}

}

// this is the line that calls the specified function
// in this case “countDownSeconds” and it calls it every
// 1000 milliseconds in this case.

var myInterval = setInterval(countDownSeconds, 1000);

 

First look inside the .fla and then inside the mc_button_primary and notice there is a little code inside there. Won’t work like you want to without it. You can add it to each instance via the myMethod() but it’s meant to be a button so let’s make this as simple as we can and put it here.

stop();
this.buttonMode = true;
this.mouseChildren = false;

StarterClass.as
Here is where something actually happens follow the comments.

package {

// here is the Adobe provided code that you need to import to make this happen
// get used to it. You'll be doing this alot.
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.*;

// import our fancy button from the library
import mc_button_primary;

public class StarterClass extends MovieClip {

// here's where our new button is born
private var buttonPrimary:mc_button_primary;

// this is the constructor, it is the function/method that is automatically called
function StarterClass() {

trace(“Starter class…..√ check”);

// call myMethod and create a button
myMethod();

}

function myMethod() {

trace(” myMethod……….√ check”);
trace(” StarterClass called myMethod()”);
trace(” myMethod() creates a button”);

// create a new button from the exported library item
buttonPrimary = new mc_button_primary();

// name the new button
buttonPrimary.name = “Linus”;

// put Linus on the stage
addChild( buttonPrimary );

// create a handle to reference Linus with
var bttn_handle = getChildByName( buttonPrimary.name );

// Put the name in the text field then center Linus on the stage
bttn_handle.button_Text.text = buttonPrimary.name;
bttn_handle.x = ( stage.stageWidth - bttn_handle.width ) / 2;
bttn_handle.y = ( stage.stageHeight - bttn_handle.height ) / 2;

// add an event listener to Linus so we know when he was clicked
bttn_handle.addEventListener( MouseEvent.CLICK, myButton_CLICK );

}

// here is the listener
function myButton_CLICK(e:MouseEvent):void {

trace(” myButton_CLICK is called when the button is clicked”);

}

}

}

StarterClass_wButton.zip

The only thing to do in the .fla is add “StarterClass” in the Document Class field under properties or under Publish Settings > Flash > Settings >Document Class. The actionscript has to be Version 3.

package {

import flash.display.MovieClip;

public class StarterClass extends MovieClip {

public function StarterClass() {

trace(“Starter class…..√ check”);

myMethod();

}

private function myMethod():void {

trace(“myMethod……….√ check”);

}

}

}

starter_class.zip