loading assets using SWCs (in Actionscript projects)

17 06 2009

Found a good article and discussions on using asset SWCs using Flash IDE:
http://www.airtightinteractive.com/news/?p=327

Advertisements




How to include Flash code packages (SWC) in Flex Builder (3)

10 06 2009

I like combining gs.TweenLite and fl.transitions.easing.* to do most of my animations. Here is how you can include the Flash AS3 library SWC in the Actionscript project library path. Step-by-step instructions are as following and also illustrated in the screenshot.

[+] In Flex Builder (3), select the Actionscript project you need to use the Flash AS3 library SWC in and edit its properties by right-click the name of the project.

[+] Select Actionscript Build Path and then the Library path tab.

[+] Click on the button that says Add SWC.

Refer to the screenshot. (I am on a MAC. the path to your SWC might be a little different.)

Enjoy.





Process of updating a Flash banner

9 01 2009

To update a Flash banner sounds simple enough however the process involves as many components as working on a small website. The resulting file size is small, but it doesn’t mean the process is easy to deal with. Most of the times when I work on banners, I forget one or two elements in the beginning which slows down the process down the road. (I know, I need to learn to like banners more…)

No matter how much I don’t like updating banners developed by other developers, they just keep coming back. So I figure I’d post the checklist of the necessary steps here in order to ensure smoother process next time.

[+] Assets. Make sure you have all the following to begin with. Believe it or not, this step takes longer than I expect every single time.
A. comp (.psd and/or .ai) and storyboards (.pdf or .psd)
B. font files (must be MAC or PC specific)
C. information on max file size (? KB)
D. information on max duration and number of loops
E. information on click through URLs (sometimes you don’t need the actually URL, instead you just need to include the clicktag code before publishing.)
F. .fla files (and which version of Flash IDE it requires.)
G. (if applicable) .as files

[+] Update the banner(s). This is always the easy part fortunately. 🙂

[+] Post the updated banners to a server so the less tech-savvy clients can check it out.

[+] Deliver the source files including
A. font files (must be MAC or PC specific)
B. .fla files (and which version of Flash IDE it requires.)
C. (if applicable) .as files





How to use Flash component (SWC) in Flex (3)

10 11 2008

It is fairly easy to import Flash components into Flex projects. The trick is to include the SWC in the Flex project library path. Step-by-step instructions are as following and also illustrated in the screenshot.

[+] In Flex (3), just select the Actionscript project you need to use the Flash SWC in and edit its properties.

[+] Select ActionScript Build Path and then the Library path tab.

[+] Click on the button that says Add SWC.

Refer to the screenshot here. (I am on a MAC, the path to your SWC might be a little different.)

Enjoy.





source – Countdown display including year and month information(AS2)

7 11 2008

Per requested, below is a screenshot of the sample .fla file showing how to use the CountDown class. (I wish we could attach zip files to wordpress blogs. Oh well.)

sample fla file of CountDown class

sample fla file of CountDown class

Basically I have only one MovieClip on the stage, with an instance name “display”. Make sure this MovieClip’s linkage links to the Class “CountDownDisplay”, which can be found in my previous post. In the actionscript layer, I have a line of code as the following:

display.init( 2012,2,28,0,0,0,0,0, 100);

You are welcome to attach the MovieClip with code instead of placing it on stage directly. Actually that is recommended b/c you can get rid of it later by using the following line of code then the removeMovieClip method:

display.kill();

For the complete class files, see the previous post.





example: Countdown display including year and month information(AS2)

17 07 2008

[UPDATE] I have uploaded a screenshot of a sample source file for your reference. Please check it out. 🙂 Thanks for the comments.

Very few code examples I could find online have included the number of years and months in them. So I thought I’d come up with my own. It is currently in AS2, leave a comment if you need an AS3 version.

[+] DateUtils class. The function getCountDown takes 2 Date objects and returns a generic object which includes the number of years, months, days, hours, minutes, seconds and milliseconds of the time that is spent to get to the end Date from the start Date. See below.

class DateUtils {
	private static var NUM_MSEC_IN_SECOND:Number = 1000;
	private static var NUM_SEC_IN_MINUTE:Number = 60;
	private static var NUM_MIN_IN_HOUR:Number = 60;
	private static var NUM_HOUR_IN_DAY:Number = 24;
	private static var NUM_MON_IN_YEAR:Number = 12;
	private static var NUM_OF_UNITS:Number = 7; // year, month, day, hours, minutes, seconds, millisesconds

	public static function getCountDown(start:Date,end:Date):Object {
		//trace ("DateUtils, getCountDown of start date:" + start+", end date:"+end);
		if (start == undefined || start == null) start = new Date();
		if (end == undefined || end == null) end = new Date();

		//if the end date is no later than start date, return 0s as results.
		if (end.getTime() - start.getTime()<=0)  return {year:0,month:0,day:0,hour:0,minute:0,second:0,millisecond:0};

		//if the end date is later than start date, continue to do the calculation
		var eY:Number = end.getFullYear();
		var eMon:Number = end.getMonth();
		//
		var start_ary:Array = &#91;start.getMilliseconds(),start.getSeconds(),start.getMinutes(),start.getHours(),start.getDate(),start.getMonth(),start.getFullYear()&#93;;
		var end_ary:Array = &#91;end.getMilliseconds(),end.getSeconds(),end.getMinutes(),end.getHours(),end.getDate(),end.getMonth(),end.getFullYear()&#93;;
		var period_ary:Array = new Array();
		var convsRate_ary:Array = &#91;NUM_MSEC_IN_SECOND,NUM_SEC_IN_MINUTE,NUM_MIN_IN_HOUR,NUM_HOUR_IN_DAY,NaN,NUM_MON_IN_YEAR,0&#93;

		for (var i:Number=0; i<NUM_OF_UNITS; i++)
		{
			period_ary&#91;i&#93;=end_ary&#91;i&#93;-start_ary&#91;i&#93;;
		}
		for (var i:Number=0; i<NUM_OF_UNITS; i++)
		{
			if (period_ary&#91;i&#93;<0)
			{
				period_ary&#91;i+1&#93; -= 1;
				if (convsRate_ary&#91;i&#93; == NaN) convsRate_ary&#91;i&#93; = (eMon>0)?getNumDaysInMonth(eY,eMon-1):getNumDaysInMonth(eY-1,eMon-1+NUM_MON_IN_YEAR);
				period_ary[i] += convsRate_ary[i];
			}
		}
		return {year:period_ary[6],month:period_ary[5],day:period_ary[4],hour:period_ary[3],minute:period_ary[2],second:period_ary[1],millisecond:period_ary[0]}
	}

	public static function getNumDaysInMonth(year:Number,month:Number):Number
	{
		if (month<0 || month>=NUM_MON_IN_YEAR) return 0;
		var firstDayInThisMonth:Date = new Date(year,month,1);
		var firstDayInNextMonth:Date = (month<NUM_MON_IN_YEAR-1) ? new Date(year,month+1,1) : new Date(year+1,month+1-NUM_MON_IN_YEAR,1);
		var numDays:Number = (firstDayInNextMonth.getTime() - firstDayInThisMonth.getTime()) / NUM_MSEC_IN_SECOND / NUM_SEC_IN_MINUTE / NUM_MIN_IN_HOUR / NUM_HOUR_IN_DAY;
		return Math.floor(numDays);
	}
}
&#91;/sourcecode&#93;

&#91;+&#93; CountDownDisplay class. It extends MovieClip and has a TextField on its timeline, with the instance name "txt". The function <em>init</em> takes a target <strong>Date</strong> object to count down (from today) to, and the frequency (in milliseconds) to update the display. The function <em>kill</em> clears the interval.

import mx.utils.Delegate;

class CountDownDisplay extends MovieClip {
	public var txt:TextField;
	private var _intvl:Number;
	private var _frqc:Number;
	private var _tDate:Date;
	private static var DIVIDING_SYMBOL:String = ":";

	private function CountDownDisplay() {}
	public function init(targetDate:Date, frequency:Number):Void
	{
		_tDate = targetDate;
		_frqc = (frequency==0 || frequency==undefined)?100:frequency;
		//this.onEnterFrame = Delegate.create(this,update);
		_intvl = setInterval(Delegate.create(this,update),frequency);
	}
	public function kill():Void
	{
		if (_intvl != undefined) 		clearInterval(_intvl);
	}
	private function update():Void
	{
		clearInterval(_intvl);
		_intvl = undefined;
		var obj:Object = DateUtils.getCountDown(new Date(),_tDate);
		var y:String = obj.year.toString();
		var mon:String = obj.month.toString();
		var d:String = obj.day.toString();
		var h:String = obj.hour.toString();
		var m:String = obj.minute.toString();
		var s:String = obj.second.toString();
		var ms:String = (Math.floor((obj.millisecond) / 10)).toString();

		y = toTwoDigit(y);
		mon = toTwoDigit(mon);
		d = toTwoDigit(d);
		h = toTwoDigit(h);
		m = toTwoDigit(m);
		s = toTwoDigit(s);
		ms = toTwoDigit(ms);

		txt.text = y+DIVIDING_SYMBOL+mon+DIVIDING_SYMBOL+d+DIVIDING_SYMBOL+h+DIVIDING_SYMBOL+m+DIVIDING_SYMBOL+s+DIVIDING_SYMBOL+ms;
		updateAfterEvent();
		_intvl = setInterval(Delegate.create(this,update),_frqc);
	}

	private function toTwoDigit ( str:String ) : String
	{
		var new_str:String = str;
		switch (true)
		{
			case Boolean(str.length==0):
				new_str = "00";
				break;
			case Boolean(str.length==1):
				new_str = "0"+str;
				break;
			case Boolean(str.length>2):
				new_str = "**";
				break;
		}
		return new_str;
	}
}

There you go. I’d be happy to send you a .fla file as an example. Let me know please.





Flash tracer stopped working ? -remedy

19 06 2008

Flash tracer, which has been my savior for the past 1.5 years, updated itself today and stopped working ever since. I tried all kinds of tricks but failed.

I have helped numerous developers to set up Flash Tracer during the time I benefit from it and every time it works like a charm… Not this time though… I can get traces in Flash Tracer if I am debugging inside Flash IDE, nothing if I have a Flash website open in Firefox. So I guess it might be a sandbox issue?

I am on Mac OS X version 10.4.11, Firefox version 2.0.0.12. If that makes a difference. My log file is saved at /Users/{user name with no weird characters} /Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt. I have mm.cfg file saved at /Users/{user name with no weird characters} /Library/Application\ Support/Macromedia/mm.cfg as well as /Users/{user name with no weird characters}/mm.cfg .

Thanks Alessandro, for saving my life millions of times.

[update] I just made my Flash Tracer work today. Here is what I did: I created the log file at the directory above, then uninstalled and reinstalled the Flash Player. (Why didn’t I think of that before?)