get Date and Time AS3

var today_date:Date = new Date();
var thismonth:uint = today_date.getMonth();
var today_time;
var currentTime:Date = new Date();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var hours = currentTime.getHours() * 30 + currentTime.getMinutes() / 2;

var mnth:Array = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var fileName:String = (today_date.getDate()+mnth[thismonth]+today_date.getFullYear()+"_"+currentTime.hours + currentTime.minutes + currentTime.seconds);
trace(fileName);// displays current date in United States date format



/*var now:Date = new Date();
trace(now.getTime());
trace(now.valueOf());
var fileName = now.valueOf().toString();*/

Rotating Banner - Save $10

stop();

/*
=======================================
NOTE: ALL SWF FILES must b AS3 exported
http://www.beautifycode.com/the-finer-art-of-loading-2-handling-multiple-swfs#snippet
=======================================
*/
import flash.events.*;
import flash.display.*;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;

import fl.motion.Color;
import flash.geom.ColorTransform;
var cTransform:ColorTransform = transform.colorTransform;
var _tintColor:Color;
var _Colored:Color;



var i:uint;
var myXML:XML = new XML();
var XML_URL:String = "banner.xml";
var indexSWF = 0;

var frames:Number;
var _swfLoader:Loader;
var _swfRequest:URLRequest;
var _swfClipsArr:Array = new Array();
var _swfTempClip:MovieClip;
var _loadedSWFs:int;
var _swfToAdd:MovieClip;
var index = 0;

var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

function xmlLoaded(event:Event):void
{

myXML = XML(myLoader.data);

/*
=============
METHOD - I
=============
*/
//call link in XML Banner tag
//Converting XML LIST into XML Array
var bannerList:XMLList = myXML.banner.link;
var BannerArray:Array = new Array();

for each (var tempXML:XML in bannerList)
{
BannerArray.push(tempXML);
}

/*
=============
METHOD - II
=============
*/
//var BannerArray:Array = new Array("00.swf", "01.swf", "02.swf");

/*
=============
METHOD - III
=============
*/

/* var arrayLoader:Loader = new Loader;
var thisMovieClip:MovieClip;
var frames:Number
var swf_URL:String = "rbd_fastsaver.swf";
var swfURL:URLRequest = new URLRequest(swf_URL);
arrayLoader.load(swfURL)*/


/*
=============
*/

startLoading(BannerArray);

function startLoading(pathArr:Array):void {
_swfLoader = new Loader();
_swfRequest = new URLRequest();
loadSWF(pathArr[0]);
//trace (loadSWF(pathArr[0])); //rbd_generic.swf
}

function loadSWF(path:String):void {
//checking contentLoaderInfo
setupListeners(_swfLoader.contentLoaderInfo);


_swfRequest.url = path;
//trace(_swfRequest.url);//*.swf
_swfLoader.load(_swfRequest);

}

function setupListeners(dispatcher:IEventDispatcher):void {

dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
}


function currentSwfProgress(event:ProgressEvent):void {
var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
// swfPreloader.percentTF.text = _perc + "%";
}


//
function onSwfComplete(event:Event):void {
event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);

_swfTempClip = event.target.content;
_swfTempClip.customID = _loadedSWFs;

//trace("ID: " + _swfTempClip.customID);

_swfClipsArr.push(_swfTempClip);

//trace(_loadedSWFs);

if(_loadedSWFs 0)
{
var data2 = "banner_btn" + index ;
_swfToAdd = _swfClipsArr[index];

trace(String(data2));

_tintColor = new Color();
_tintColor.setTint (0,0);

banner_btn0.transform.colorTransform = _tintColor;
banner_btn1.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;

if (this[String(data2)]){


_Colored = new Color();
_Colored.setTint (0x000000,1);
this[String(data2)].transform.colorTransform = _Colored;
//banner_btn2.transform.colorTransform = _Colored;
}





}

if (index >= _swfClipsArr.length)
{
index = 0;
banner_btn0.transform.colorTransform = _Colored;
_swfToAdd = _swfClipsArr[index];

}
movie1.removeChildAt(movie1.numChildren-1);
_swfToAdd.gotoAndStop(_swfToAdd.totalFrames);
_swfToAdd.gotoAndPlay(1);
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);


}

}







Color Transform

import fl.motion.Color;
var square:Sprite = new Sprite();
square.graphics.beginFill(0x000000);
square.graphics.drawRect(100, 100, 100, 100);
addChild(square);
square.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
square.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
function onMouseOver (e:MouseEvent):void
{
var c:Color = new Color();
c.setTint (0x929218, 1);
square.transform.colorTransform = c;
}
function onMouseOut (e:MouseEvent):void
{
var c:Color = new Color();
c.setTint (0, 0);
square.transform.colorTransform = c;
}


CodeLink

http://codes.creativebrain.ca

Get Current Frame

textBox.addEventListener(Event.ENTER_FRAME, frameNumberText);
function frameNumberText(evt:Event):void {
var frames:Number;
frames=currentFrame;
textBox.text = (String(frames));
}

loading swf from XML

http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=1

stop();

import flash.events.*;
import flash.display.*

var i:uint;
var myXML:XML = new XML();
var XML_URL:String = "banner.xml";

var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

function xmlLoaded(event:Event):void {

myXML = XML(myLoader.data);
//xml have banner tag
var banner1:String = myXML.banner.link[0];
var banner2:String = myXML.banner.link[1];
var banner3:String = myXML.banner.link[2];
var banner4:String = myXML.banner.link[3];
var banner5:String = myXML.banner.link[4];
var banner6:String = myXML.banner.link[5];


var loader1:Loader = new Loader();
movie1.addChild(loader1);
var banner_url1:URLRequest = new URLRequest(banner1);
loader1.load(banner_url1);


banner_btn1.addEventListener(MouseEvent.CLICK, Btn_1);
banner_btn2.addEventListener(MouseEvent.CLICK, Btn_2);
banner_btn3.addEventListener(MouseEvent.CLICK, Btn_3);
banner_btn4.addEventListener(MouseEvent.CLICK, Btn_4);
banner_btn5.addEventListener(MouseEvent.CLICK, Btn_5);
banner_btn6.addEventListener(MouseEvent.CLICK, Btn_6);



function Btn_1(e:MouseEvent):void {
var banner_url1:URLRequest = new URLRequest(banner1);
loader1.load(banner_url1);
}

function Btn_2(e:MouseEvent):void {
var banner_url2:URLRequest = new URLRequest(banner2);
loader1.load(banner_url2);
}

function Btn_3(e:MouseEvent):void {
var banner_url3:URLRequest = new URLRequest(banner3);
loader1.load(banner_url3);
}

function Btn_4(e:MouseEvent):void {
var banner_url4:URLRequest = new URLRequest(banner4);
loader1.load(banner_url4);
}

function Btn_5(e:MouseEvent):void {
var banner_url5:URLRequest = new URLRequest(banner5);
loader1.load(banner_url5);
}

function Btn_6(e:MouseEvent):void {
var banner_url6:URLRequest = new URLRequest(banner6);
loader1.load(banner_url6);
}

}

/*
===================================================
http://onerutter.com/flash/flash-actionscript-30-xml-text-array-loader.html
http://www.kirupa.com/forum/showthread.php?t=308712
http://www.flepstudio.org/forum/actionscript-3-0-newbies/5073-loading-multiple-swf-s-arrays-as3.html
http://board.flashkit.com/board/showthread.php?t=776675
===================================================
xml version="1.0" encoding="utf-8"
//    rakbank>
//   
//        banner name="banner1" url="index.html"//
                  name>Banner Generic
                  link>1.swf
//                target>_self
                  banner
//    rakbank>

SmartFoxServer JoinRoom

stop();
import it.gotoandplay.smartfoxserver.*;
import it.gotoandplay.smartfoxserver.data.*;

sfs.addEventListener(SFSEvent.onConnection,onConnection);
sfs.addEventListener(SFSEvent.onJoinRoom, onJoinRoomHandler);

msg.text="";
msg2.text="";

gameUser.text = "AK";
var User_name:String = gameUser.text;
var joinedRoom:Room;

function onConnection(e:SFSEvent):void
{
sfs.login(sfs.defaultZone, User_name ,"");
//sfs.login(zeon,nickname,passwword);
msg2.text = "Status - " + (sfs.isConnected ? "connected" : "not connected");

//trace("My user ID is: " + sfs.myUserId);
//trace("My user Name is: " + sfs.myUserName);
}

function onJoinRoomHandler(e:SFSEvent):void
{
joinedRoom = e.params.room;
//Current room name and ID
msg.text= joinedRoom.getName()
+" room joined successfully" ;
//+"Room ID : " + joinedRoom.getId();

var users:Array = joinedRoom.getUserList()
for (var u:String in users)
User_list.text =(users[u].getName());


}


sfs.addEventListener(SFSEvent.onUserCountChange, onUserCountChangeHandler)

function onUserCountChangeHandler(evt:SFSEvent):void
{
// Assuming this is a game room

var roomName:String = evt.params.room.getName()
var playersNum:int = evt.params.room.getUserCount()
var spectatorsNum:int = evt.params.room.getSpectatorCount()

trace("Room " + roomName + "has " + playersNum + " players and " + spectatorsNum + " spectators")
}

SmartFoxServer Connection XML config file

stop();

import it.gotoandplay.smartfoxserver.*;
import it.gotoandplay.smartfoxserver.data.*;

var sfs:SmartFoxClient = new SmartFoxClient();
//load config file
sfs.addEventListener(SFSEvent.onConfigLoadSuccess, onConfigLoadSuccessHandler);
sfs.addEventListener(SFSEvent.onConfigLoadFailure, onConfigLoadFailureHandler);
sfs.addEventListener(SFSEvent.onRoomListUpdate,onRoomListUpdate);
sfs.loadConfig("config.xml", false);

msg.text="";

function onConfigLoadSuccessHandler(evt:SFSEvent):void
{
msg.text = "Config file loaded, now connected...";
sfs.connect(sfs.ipAddress, sfs.port);
gotoAndStop("cRoom", "Scene 1");

}

function onConfigLoadFailureHandler(evt:SFSEvent):void
{
msg.text = "Failed loading config file: " + evt.params.message;
}

function onRoomListUpdate(e:SFSEvent):void
{
sfs.autoJoin();

}

Flash Effect

diferent Clicktags

//AS3
//EYEBLASTER

import flash.events.MouseEvent;
import flash.system.fscommand;

click_btn.addEventListener(MouseEvent.CLICK,funcionClick);
function funcionClick(e:Event):void{
fscommand("ebInteraction");
};


//AS3
//EYEBLASTER

import flash.events.MouseEvent;

click_btn.addEventListener(MouseEvent.CLICK,funcionClick);
function funcionClick(e:Event):void{
EB.Clickthrough();
};


//AS3
//MSN

import flash.events.MouseEvent;

var tag:URLRequest = new URLRequest();
tag.url = clickTAG;

click_btn.addEventListener(MouseEvent.CLICK,funcionClick);
function funcionClick(e:Event):void{
navigateToURL(new URLRequest(tag),”_blank”);
};


//AS3
//MSN

import flash.events.MouseEvent;
import flash.system.fscommand;

click_btn.addEventListener(MouseEvent.CLICK,funcionClick);
function funcionClick(e:Event):void{
fscommand("URL1");
};


//AS3
//YAHOO

import flash.events.MouseEvent;

var tag:URLRequest = new URLRequest();
tag.url = clickTAG;

click_btn.addEventListener(MouseEvent.CLICK,funcionClick);
function funcionClick(e:Event):void{
navigateToURL(new URLRequest(tag),”_blank”);
};


http://www.flashkode.es

XML in flash

stop();
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("banner.xml"));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
trace(xmlData);

}

//load swf
var myLoader:Loader = new Loader();
move1.addChild(myLoader);
var url:URLRequest = new URLRequest("rbd_motorinsurance.swf");
myLoader.load(url);

flash xml button and mouse detection


Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player



Calling flash button from XML i.e. below code
stop();
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.load(new URLRequest("link.xml"));

function showXML(e:Event):void {
XML.ignoreWhitespace = true;
var songs:XML = new XML(e.target.data);
var number1 = songs.menu.link[0];

removeEventListener(Event.ENTER_FRAME,myFunction);
btn_next.addEventListener(MouseEvent.CLICK, myBtnClicked);

function myBtnClicked(e:MouseEvent):void {
gotoAndPlay(1,"ad2");
trace(number1);
var url:URLRequest = new URLRequest(number1);
navigateToURL(url,"_self");

}

Detect Mouse on stage

getgoing();

function getgoing() {
   
addEventListener(Event.ENTER_FRAME,myFunction);   
}


function myFunction(event:Event) {
   
    if( mouseY < 100){
       
        mc.y = -3;
        mc.x = -14;
        gotoAndPlay("done","ad1");
       
        }   
    else
    {
    mc.y = 100;
    var midPt:uint = 100;
    var diff:int = mouseY - midPt;
    var perc:Number = diff / midPt;
    var maxSpeed:uint = 100;
    mc.y += perc * maxSpeed;
       
    }
}


//1.
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePosition);

//2.
function mousePosition(event:MouseEvent) {
//trace(String(mouseX));
//xstage_txt.text= String(mouseX);
//ystage_txt.text= "Y Stage: " + String(mouseY);

//xmovie_txt.text= "X MovieClip: " + String(box_mc.mouseX);
//ymovie_txt.text= "Y MovieClip: " + String(box_mc.mouseY);

}

Hide mouse
   
//Mouse.hide();   
//stage.addEventListener (MouseEvent.MOUSE_MOVE, dragCursor);

    function dragCursor (event:MouseEvent):void
    {
    mypointer.x = this.mouseX;
    mypointer.y = this.mouseY;
    }

XML file

Popup window

on (release) {
getURL ("javascript:NewWindow=window.open('ShowPopup.php','newWin','width=400,height=300,left=0,top=0,
toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No'); NewWindow.focus();
void(0);");
}


getURL/navigateToURL

ActionScript 2.0:
getURL("www.adobe.com", "_blank");

ActionScript 3 .0:
var url:URLRequest = new URLRequest("http://www.adobe.com"); navigateToURL(url, "_blank");

getURL/navigateToURL with JavaScript


ActionScript 2 .0:

var jscommand:String = "window.open('http://www.adobe.com','win','height=200,width=300,toolbar=no,scrollbars=yes');"; getURL("javascript:" + jscommand + " void(0);");

ActionScript 3 .0:

var jscommand:String = "window.open('http://www.adobe.com','win','height=200,width=300,toolbar=no,scrollbars=yes');"; var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);"); navigateToURL(url, "_self");

Read more

delay timeout

stop();
setTimeout(timedFunction,1000);
 
function timedFunction() {
 gotoAndStop(2);
}

Flash&Flex Developer's Magazine - FFD

Flash&Flex Developer's Magazine – March 2010 issue

In the issue:
- Delivering video for Flash Player 10.1 on mobile devices
- Why the iPad Will Redefine Our View of RIAs
- Flex and Air
- Understanding Flex 4 components
- Flex and Jabber
- Dynamic Views and Mediators with PureMVC
- Deeplinking your Flash and Flex applications with SWFAddress
- What Kind of Website Should I Make?
- Project Organization Best Practices
- Dive into OSMF-Part One
- A Case for Streaming Media and the Cloud
- Readers BUG - Readers Q&A section
- ...and much more inside...

Delay Timer

// Requires a movieclip with the instance name "objectMC" to be on the stage

var myTimer:Timer = new Timer(6000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();

function timerHandler(evt:TimerEvent):void
{
car.x = 200;
car.y = 200;
}

//myTimer.stop();

Valid Email in AS3

txt1.text="";
custdetails_btn.addEventListener(MouseEvent.CLICK, popup);
function popup(event:MouseEvent):void {
if( cust_name.text=="" || cust_email.text == "" )
{ txt1.text="Please enter Name and Email";
}

else if(cust_email.text == "" ||
cust_email.text.indexOf("@") < 0 || cust_email.text.indexOf(".") < 0 || cust_email.text.indexOf(" ") > 0 )
{
txt1.text="Please enter valid email";
}
else
{
MovieClip(root).play();
}
}

Play from inside movieclip

custdetails_btn.addEventListener(MouseEvent.CLICK, popup);

function popup(event:MouseEvent):void {
MovieClip(root).play();
}

GET URL

btn_intro.buttonMode = true;
btn_intro.addEventListener(MouseEvent.CLICK, myBtnClicked);

function myBtnClicked(e:MouseEvent):void {
var url:URLRequest = new URLRequest("myweekend.html");
navigateToURL(url,"_self");
}