Archive for the ‘Flash’ Category

Using the Date Object

Sometimes it is necessary to display information within Flash on certain days only, until a certain or only after a certain date has passed. This is a simple ActionScript test to set up todays date in the following format “YearMonthDate”. Example. 20050402 for today.

[as]
var testDate1 = “20050306″; // March 6th, 2005
var testDate2 = “20050406″; // April 6th, 2005

// create Date object
var now:Date = new Date();

// call Month, Day, and FullYear methods
var Month = now.getMonth() + 1; // Month is zero index, so add 1
var Day = now.getDate();
var Year = now.getFullYear();

// Add zero(0) to front of Month or Day if less than 10
Month = (Month< =9) ? "0"+Month : Month +""; // Month + "" is to force String
Day = (Day<=9) ? "0"+Day : Day + ""; // Day + "" is to force String

// combine into full string
var today:String = Year+Month+Day;

trace(today);

// simple test of testDate1
if (today >= testDate1) {
trace(“Today matches or exceeds the test date =>(“+testDate1+”).”);
} else {
trace(“Today is not quite enough. test date =>(“+testDate1+”).”);
}

// simple test of testDate2
if (today >= testDate2) {
trace(“Today matches or exceeds the test date =>(“+testDate2+”).”);
} else {
trace(“Today is not quite enough. test date =>(“+testDate2+”).”);
}
[/as]

Extending mx.transitions.Tween

This is a really cool AS 2.0 class for extending the mx.transitions.Tween class to pass multiple properties. I wish I had know about this before. I just finished up a small project where I was doing multiple lines of mx.transistions.Tween when I didn’t need to be.

Here is some sample code on using the mx.transitions.TweenExtended once you installed it. This sample is moving the movieClip, ball_mc, to the position of 700×400 and also modifying its _alpha property. All in one line of code. Nice!!!
[as]
// import the Class
import mx.transitions.TweenExtended;
// I like defining the easingType as a variable, but it could be directly in the new TweenExtended line
easingType = mx.transitions.easing.Back.easeOut;
extendTween = new TweenExtended(ball_mc,["_x","_y","_alpha"],easingType,[ball_mc._x,ball_mc._y,ball_mc._alpha],[700,400,25],2,true);
[/as]

The file is available for download from Square Circle Solutions [ link ]. Check the page out because there is some other cool stuff there as well.

(original story via FlashGuru)
One of the main features that the Macromedia Tween Class is lacking, is the ability to tween multiple properties of a movieclip using one instance of the tween class. My friend George has released a TweenExtended class that extends the Macromedia mx.transitions.Tween code allowing you to tween multiple properties with one instance of the class and alot less code.

You can download the class and many more goodies at our website:

http://www.sqcircle.com/downloads/

Basic XML with Flash

Someone had asked me today how to use XML with Flash. He is interested in using a XML file to configure a game he wants to write. He wants to write a Monopoly-like game but be able to quickly reconfigure the game board based on the location he wants to use. I wrote up a very basic sample file for him and I thought I would share it here.

[as]
var myXML:XML = new XML(‘‘);

trace(“Number of board nodes=”+myXML.firstChild.childNodes.length);
numNodes = myXML.firstChild.childNodes.length;
for (i=0;i trace(myXML.firstChild.childNodes[i].attributes.name +” has a rent of $”+myXML.firstChild.childNodes[i].attributes.rent);
}
[/as]

Now this sample uses XML directly within the ActionScript, but it is done the same way using external XML, except you would have a myXML.load(“config.xml”) and then need a myXML.onLoad function handler.

ActionScript — Use mx.transitions.Tween

Using the mx.transitions Class is very easy and a simple way to tween stuff that used to take a LOT longer to do the “old-way”.

Syntax:

referenceID = new mx.transistions.Tween( InstanceName, “_property”, easingType, beginning value, ending value, # of frames or seconds, boolean);

Example:

[as]

easeType = mx.transitions.easing.Strong.easeOut;
myTween = new mx.transitions.Tween(myMovieClip_mc, “_x”,easeType, 0, 600, 20);

// onMotionFinished is called when the tween is complete
myTween.onMotionFinished = function() {
trace(“myMovieClip_mc has finished moving.”);
};
[/as]

A really good tutorial on mx.transitions is available over at ActionScript.org

AdminTool – remote flash debugging

If you haven’t looked into AdminTool, the remote Flash debugger, you need to. It comes with a connector (MXP) and the AdminTool Interface (mac and pc).

Admin Tool

It allows you to remotely browse your Flash SWF, look at parent/child relationships, view properties and methods, call those methods and change those properties, and a lot more. All of this and minimal impact on performance. This is a really great tool.

Return top