Calculate date difference in AS

Calculating how many days are left to a future date is very simple (both in AS2 and AS3).

This is how you can calculate how many days are left for new year:

Actionscript:
  1. var today:Date = new Date(); // now
  2. var target:Date = new Date(2011, 0, 1, 0, 0, 0, 0); // Sat Jan 1 00:00:00 GMT+0000 2011
  3. // number of milliseconds between the two dates
  4. var milliseconds:Number = target.getTime() - today.getTime();
  5. // make sure it's in the future
  6. if (milliseconds> 0)
  7. {
  8.     var seconds:Number = milliseconds / 1000;
  9.     var minutes:Number = seconds / 60;
  10.     var hours:Number = minutes / 60;
  11.     var days:Number = Math.floor(hours / 24);
  12.    
  13.     trace("days left: " + days);
  14.    
  15.     if (days == 0)
  16.     trace("it's today!!");
  17. }
  18. else
  19. {
  20.     trace("not in the future");
  21. }

Posted in ActionScript, Flash, Tutorial | Leave a comment

Creating a SWC with FlashDevelop

In order to create a SWC using FlashDevelop you can use the ExportSWC plugin.
This makes the process really simple.

I was wondering how I could create a SWC like the one available in the AS3 Core Lib for example.

You need to have FlashDevelop and the Flex SDK.

At the time of this writing the current version of FlashDevelop is 3.2.1, of ExportSWC is 1.2.3803.31343 and of the Flex SDK is 4.1.

If you need instructions on how to configure FlashDevelop with the Flex SDK, here you have the info you need. Although it’s for an older version of the Flex SDK, the steps are all the same.

In order to install the plugin, just download and double click it. Follow the steps and that’s it.
The next time you open FlashDevelop you’ll see a new button in the toolbar.

toolbar

Create a new project:
Project->New Project->AS3 Project
Choose a name for the project, set the Location and define a package.

project box

You’ll end up with this:
project

If you click the SWC/MXI button in the toolbar, the new SWC will appear in the “bin” folder.

project

This is it.

In this case, you only have the Main.as Class in the src/com/mydomain/test/ folder, which is created automatically, but you can have all the Classes you want.
Just make sure you have all the Classes that are required for the compilation. At a certain time I didn’t, and The SWC file wasn’t being created. it just failed silently.

Posted in AS3, ActionScript, Flash, FlashDevelop, Tutorial | Leave a comment

Animated MovieClip on MOUSE_OVER, MOUSE_OUT


If you want to have better looking animations in buttons, you don't use a Button, you use a MovieClip.
This means that you'll have to use some code to control the MovieClip. Play it forwards on mouse over, play it backwards on mouse out.

Continue reading

Posted in AS3, ActionScript, Flash, Tutorial | Leave a comment

Apply and Remove tint to an Object in AS3

If you want to tint an object and then revert to its original color, you can use setTint() passing 0 in the second parameter, e.g.:

Actionscript:
  1. c.setTint (0xFF0000, 0);

Continue reading

Posted in AS3, ActionScript, Flash | Leave a comment

convert Decimal to Hex and back

In Flash (AS3), when you store a colour in a variable, although the 0x specifies an hexadecimal value, the variable will be of type uint (unsigned integer).

Actionscript:
  1. var c:uint = 0xFFFFFF;

This means that Flash, internally, converts the hexadecimal value to decimal.
You can easily verify this by tracing this variable's value:

Actionscript:
  1. trace (c); // 16777215

What if you want to convert this decimal value back to hexadecimal?
You use toString() and pass the parameter 16:

Actionscript:
  1. trace (c.toString(16)); // ffffff

Notice that what you get is a string.
If you want to have 0xFFFFFF instead of ffffff, all it takes is some very simple string manipulation:

Actionscript:
  1. trace("0x" + c.toString(16).toUpperCase()); // 0xFFFFFF

If you want to use this value in Flash, you'll have to cast it to an integer using uint():

Actionscript:
  1. trace (uint("0x" + c.toString(16).toUpperCase())); // 16777215

Here's the complete code:

Actionscript:
  1. var c:uint = 0xFFFFFF;
  2. trace (c);
  3.  
  4. var s:String = "0x" + c.toString(16).toUpperCase();
  5. trace (s);
  6.  
  7. trace (uint(s));

Posted in ActionScript | 2 Comments

New address for amfphp: amf-php.org

Due to a lot of confusing circunstances the old domain amfphp.org expired and can't be renewed, or at least it's not very likely that it will be anytime soon.

The good news is that there's a new amfphp - Flash remoting for PHP address: amf-php.org.

So, go to the new amfphp site and spread the word.

2 Comments

Adobe CS3 Installation Problems

Although the installation on my new notebook went smoothly, I didn't have the same luck with my desktop.

The installation took forever and in the end I got a error message regarding missing components.
I tried it over and over, searched the web, read and tried everything I could find.
The Creative Suite 3 cleanup script was no solution...
Then I came across this technote: 'Error "Licensing for this product has stopped working" when you start any Adobe Creative Suite 3 application' - whose title doesn't seem to have anything to do with the problem but the solution - uninstalling the Macromedia Flash Player 8 - worked.

The instructions to uninstall the Macromedia Flash Player 8 using the Windows Install Clean Up utility - msicuu2.exe - is in the middle of the technote, so make sure you read it carefully.

30 Comments

Adobe CS3 Trials available

The Adobe Creative Suite 3 Trials are finally available for download.

Get them now!

Leave a comment