Tag Archive for actionscript

Pause frame using ActionScript 2

stop();
var interval:Number = setInterval(
function():Void {
play();
clearInterval(interval);
},
10000
);

source

ClickTag using ActionScript 2

buttonClip.onRelease = function(Void):Void {
getURL(clickTag, "_blank");
}

source

Pause frame using ActionScript 3

stop();

var timer:Timer = new Timer(10000, 1);
timer.addEventListener(
TimerEvent.TIMER,
function(evt:TimerEvent):void {
play();
}
);
timer.start();

source

clickTag using ActionScript 3

clickTag_bn.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(event:MouseEvent):void {
navigateToURL(new URLRequest(clickTag), “_blank”);
}

source

Button Loop actionscript 2.0

var cur:Number;
var played:Boolean = false;

for (x = 1; x <= 3; x++)
{
eval ("clip_" + x + "_mc.hit").onRelease = play_clip;
}

function play_clip ()
{
cur = this._parent._name.charAt (5);
played = true;

for (x = 1; x <= 3; x++)
{
if (x != cur)
{
eval ("clip_" + x + "_mc")._alpha = 0;
eval ("clip_" + x + "_mc.hit").enabled = false;
}
}
//this.enabled = false;
this._parent.play ();
if (cur == 1){
pic_frames.scaleTo(233, .5, 'linear');
pic_frames.xSlideTo(124, .5, 'linear');
pic_frames.ySlideTo(-26.8, .5, 'linear');
pic_frames.frame_2.alphaTo(20, .5);
pic_frames.frame_3.alphaTo(20, .5);

}else if(cur == 2){
pic_frames.scaleTo(233, .5, 'linear');
pic_frames.xSlideTo(-500, .5, 'linear');
pic_frames.ySlideTo(-117, .5, 'linear');
pic_frames.frame_1.alphaTo(20, .5);
pic_frames.frame_3.alphaTo(20, .5);
}else{
pic_frames.scaleTo(233, .5, 'linear');
pic_frames.xSlideTo(-1119, .5, 'linear');
pic_frames.ySlideTo(-26.8, .5, 'linear');
pic_frames.frame_2.alphaTo(20, .5);
pic_frames.frame_1.alphaTo(20, .5);
}

if(played && this._parent._parent._parent.instruction_mc._alpha != 0)
{
this._parent._parent._parent.instruction_mc.alphaTo(0, .5);
}
else
{
//do nothing;
}
}

function reset ()
{
pic_frames.scaleTo(100, .5, 'linear');
pic_frames.xSlideTo(-12.1, .5, 'linear');
pic_frames.ySlideTo(24.4, .5, 'linear');
pic_frames.frame_1.alphaTo(100, .5);
pic_frames.frame_2.alphaTo(100, .5);
pic_frames.frame_3.alphaTo(100, .5);
for (x = 1; x <= 3; x++)
{
eval ("clip_" + x + "_mc").gotoAndStop (1);
eval ("clip_" + x + "_mc")._alpha = 100;
eval ("clip_" + x + "_mc.hit").enabled = true;
}
}
clip_1_mc.input_animation.enter_btn.onRelease = function() {
trace(clip_1_mc.input_animation.input_txt.text);
};

source

KeyPress/keyboard events handling in Flex AS3

public function init():void
{
txtBox.addEventListener(KeyboardEvent.KEY_UP,pressEscape);
}

public function pressEscape(event:KeyboardEvent):void
{
if (event.keyCode==13)
{
Alert.show("Enter Key has been pressed");
}
}

source

Search Displaylist for Bitmap (or any type of DisplayObject)

var bitmap:Bitmap;
for (var i:int = 0; i < this.numChildren; i++)
{
bitmap = this.getChildAt(i) as Bitmap;
if (bitmap) break;
}

source

Format Number in ActionScript

function numberFormat(number, decimals, thousands_sep, decimal_sep) {
//   var_number.number_format([decimals ,thousand separator,decimal separator]);
//   var number: number to format
//   decimals: how many decimal numbers (default value 0);
//   thousand separator: char that define the thousandecimal_sep (default value ,);
//   decimal separator: char the defines the decimals (default value .);

if(isNaN(number)) return undefined;
if(decimals < 0) return undefined;
if(decimals == undefined) decimals = 0;
if(thousands_sep == undefined) thousands_sep = ',';
if(decimal_sep == undefined) decimal_sep = '.';

var returned = number.toString().split('.'), str_begin, str_after, temp_str = "", i;

if(returned.length == 1) {
str_begin = returned[0]
str_after = '';
} else if(returned.length == 2) {
str_begin = returned[0];
str_after = returned[1];
str_after = str_after.substr(0, 2);
} else {
trace("uncaught number format");
}

// thousands seperator
if(str_begin.length > 3) {
for(i = 0; i < str_begin.length; i++) {
if(((str_begin.length - i) % 3) == 0 && i != str_begin.length - 1) {
temp_str = temp_str + thousands_sep + str_begin.charAt(i);
} else {
temp_str = temp_str + str_begin.charAt(i);
}
}
} else {
temp_str = str_begin;
}

//   ----------------------
//   decimals
//   if decimals==0 return
//   ----------------------
if(decimals > 0) {
str_after = str_after.substr(0, decimals);

if(str_after.length < decimals) {
while(str_after.length < decimals) {
str_after += '0';
}
}
}

if(decimals > 0) {
return temp_str + decimal_sep + str_after;
} else {
return temp_str;
}
}

source

actionscript – cuepoint listener for FLV video in flash

// add an event listener to the video to listen for cuepoints
// in this case the videoclip instance name is 'vid'
// if you change the instance name change the code accordingly

var listenerObject:Object = new Object();
listenerObject.cuePoint = function(eventObject:Object):Void
{

// stuff the function does goes below here

// stuff the function does goes above here

}
vid.addEventListener("cuePoint", listenerObject);

source

actionscript – trace actions to get info about cuepoints in FLV video

/* ||||||||||||||||| CUEPOINT TRACES ||||||||||||||||||||
these trace actions are handy for returning the info that flash has about any cuepoints it encounters, embedded in an FLV [flash video] file. put these traces inside a cuepoint listener function to test whether flash is picking up the cuepoints in the first place, before you add any more complicated code.  these traces will display:

- the 'event' the listener has detected [ie. a cuepoint]
- the name of the cuepoint
- the type of the cuepoint [ie. 'event' or 'navigation']
- the time the cuepoint sits at in the video

[note: this code assumes your FLV video file has an instance name of 'vid'.  if you change the instance name change the "this.vid.playheadTime" part of the code accordingly]
||||||||||||||||||||||||||||||||||||||||||| */

// begin traces
trace("listener detected: 	"+eventObject.type);
trace("cuepoint is called: 	"+eventObject.info.name);
trace("cuepoint is of type: 	"+eventObject.info.type);
trace("vid playhead time: 	"+vid.playheadTime);
trace("------
");
// end traces

source