Debuging is a craft in it’s own and it’s always helpful to find new tips and tricks. So, I’m writing to post about a new trick for helping us Flash coders debug our sweet, buggy code. Adobe put in a new feature in Flash CS4 called Conditional Compiling and you can read more about it from InsideRIA’s article.
The basic idea is that you can use a compiler constant called CONFIG::Debug to tell the compile when to run some code. If the constant is set to true it’ll be run if it’s set to false then it won’t. Simple, right? Before you start coding you’ll want to go into your Actionscript 3 settings and click on the last tab surprisingly called “Config constants”. Here you can create the constant and set it’s value.
Now that you are all set you you can then use code such as this to see it in action.
1
2
3
4
5
6
7
8
9
| var val:int = 0;
for (var i:int = 0; i < 200; i++)
{
val += i * .5;
CONFIG::Debug
{
trace(val);
}
} |
And that’s it. It’s a small tip but one that I’ll be definitely using from now on in my projects. If you want to see another simple example I’ve put up a zip file located here for your viewing pleasure.
So, I recently wanted to play around with the Bit.ly API and use it in flash. I decided it would be best to write up a nice little helper class. The usage for this is pretty simple and right now it only implements two of the API methods, shorten and expand. I’ll work on the other calls but I figured these were the most widely used.
1
2
3
4
5
6
7
8
9
10
11
12
| import com.imperez.apis.bitly.Bitly;
import com.imperez.apis.bitly.events.BitlyEvent;
var bitly:Bitly = new Bitly("bitly username", "user api_key");
bitly.addEventListener(BitlyEvent.SHORTEN, this._shorten);
bitly.shorten("http://www.google.com/");
function _shorten(event:BitlyEvent):void
{
var shortURL:String = event.currentTarget.shortURL;
trace(shortURL); //http://bit.ly/4BSxf
} |
As you can see from the code above it’s pretty simple. Pass in your username and api key in the constructor and then listen for the BitlyEvent.SHORTEN event. Make your call along passing your long url and you are set to go. I wanted to keep this is as easy to use as possible. I also wanted to make it so you wouldn’t need to have to parse xml in order to get this information.
And that’s it. Nothing more to see but sweet, sweet code . If you’re interested I have it up on my repository located here. There are still some bug fixes and general clean up to on top of further implementation but I would say it’s a good start.
Well, I was working a small project and I realized I needed to be able to copy content to the user’s clipboard. I know this is doable since I’ve seen it done in many, many flash sites and applications. So after a quick look through the Flash Help Docs I came across a little function called System.setClipboard().
Check out the example below to see it in action. All you have to do is type your own text and press copy. Simple and easy.
This movie requires Flash Player 9
1
2
3
4
5
6
7
8
9
10
11
12
| import flash.system.System;
import flash.events.MouseEvent;
this.copyButton.mouseChildren = false;
this.copyButton.buttonMode = true;
this.copyButton.addEventListener(MouseEvent.CLICK, this._click);
function _click(event:MouseEvent):void
{
System.setClipboard(this.copyField.text);
this.copyButton.labelField.text = "Copied!!";
} |
The way this code works is that after you’ve typed your text and press the copy button. System.setClipboard() is called and a string is passed as a parameter. And that’s really all of the grunt work. Nothing more or less.
I’ve uploaded a zip file containing all the source files for your viewing pleasure.
Hope you found this example useful!
Ever since reflections became all the craze I have always wanted to create a simple Actionscript class to… well make reflections. So I started it about a year ago and it was very scrapped together. I left it alone and then came back to it a couple months ago. I ended up re-writing a lot of it and kept tweaking it until I’ve come up with what I call, ReflectionClip. Check out the example after the jump as well as a more in depth description with code!
Read the rest of this entry »
First, I have to say this is nothing special or ground breaking. I’m mainly putting this up to hopefully remind myself of how I did this and possibly find a better way in case I need to do this in the future.
Now with that out of the way I’ll explain what I did and how I solved it. I was working on a project and in one moment I had to obtain a series of properties and it’s values from an object such as this:
var o:Object = {time: 1, color: "red", food: "cereal"};
Read the rest of this entry »