Tag: tips
Kill Those Timeouts
by Josh on Jul.01, 2008, under Flex

If you’re working on a project that’s prone to timing out on you, and throwing those “A script has executed for longer than the default timeout period of 15 seconds” errors, here’s a quick tip for you until fix the bugs causing the timeout.
Just set the scriptTimeLimit attribute of your <mx:Application> tag to a smaller value, like 3 seconds. That way you won’t need to wait around for a while waiting for your app to crash so you can get back to debugging the problem. It’ll crash in about 3 seconds instead of 15, or even a full minute later.
Obviously, the ideal solution is to fix the bug causing the timeout, but while you’re debugging, this should help to ease the pain a little bit.
LiveDocs: http://livedocs.adobe.com/flex/3/langref/mx/core/Application.html#scriptTimeLimit
AIR Installer Badge - Error #2032
by Josh on Jun.30, 2008, under AIR
While working on creating an installer badge for an AIR application I’m working on, I kept receiving the following error when trying to install the application: Error# 2032

After doing a bit of Googling, the most common solution I found was to make sure that the MIME-type for AIR was set on your server so that it would recognize the AIR filetype.
You can do this by adding the following line to the .htaccess file for your server: (I’m not a server guru, so this may not work in all cases, but it works on the Apache server I’m using.)
AddType application/vnd.adobe.air-application-installer-package+zip .air
After adding this I was still receiving the error. So… a little more time searching, and I found another piece to the solution - I had been using a relative path name in the flashVars for my installer badge. That doesn’t work. Apparently, while you can use a relative path for the thumbnail image displayed by the badge, the actual path to the .air installer file must be the full path to the file. (http://www.domain.com/pathToInstaller.air).
Since it took me a little bit longer to find that part of the solution, I wanted to post it here, just to add one more place where you might be able to find it. These aren’t the only two reasons why you could receive this error, but at least it’s two more possible solutions.
Comparing Objects Using ByteArrays
by Josh on Feb.11, 2008, under ActionScript
There have been plenty of times in projects where I’ve wanted to compare two objects to see if they are equal. I don’t really care if they are the same object, all I care about is if they are identical - meaning that they could be two unique objects, but that the values of their properties are equal to each other.
Using the Ternary Operator
by Josh on Jul.07, 2005, under ActionScript, Development, Flash
Just a quick mini-tutorial on using the ternary operator in ActionScript. One of those things that shows up in my search logs, so the next time someone searches for it, they should be able to find it.
The ActionScript Ternary Operator
The ternary operator, "? :", is basically a shorcut for writing quick conditional statements that evaluate to either true or false. Similar to an if/else statement, you use them to make a decision in your code, and act based on that decision.
Here's the syntax:
-
// using the ternary operator
-
(condition) ? isTrueAction : isFalseAction;
-
The ( ) around condition are optional, however they do help to clearly illustrate the condition. The code above is the same as writing:
-
// the same thing, only more typing
-
if (condition) {
-
isTrueAction;
-
} else {
-
isFalseAction;
-
}
-
Now, you won't be able to use this for something that has multiple statements after the condition like you can in an if statement, but it does have it's uses for quick little things. For example, you couldn't use it for something like this:
-
// this can't be written out using ternary operators
-
if (condition) {
-
isTrueAction;
-
var bob:String = "something";
-
goDoSomethingNow();
-
} else {
-
isFalseAction;
-
}
-
But it's great for something like this:
-
// this is a great use for ternary operators
-
(superBowlWon == true) ? gotoDisneyland() : goHome();
-
Or even for checking if a number is even or not.
You can also use this technique to set values for variables:
-
// setting a variable like this...
-
var pillToTake:String = (stayInMatrix == true) ? "blue" : "red";
-
//
-
// is the same as doing this:
-
if (stayInMatrix == true) {
-
var pillToTake:String = "blue";
-
} else {
-
var pillToTake:String = "red";
-
}
-
So, as you can see, using this operator can save you time by requiring less typing in a few situations. Now, it's not the solution to everything, but as you start using it more, you'll start to wonder how you worked without it. (Maybe not, but it'll make me feel better if I can imagine that I've somehow improved your life.)
Also, after I finished writing this, I decided I wanted to try and determine which method is faster, to see if there's another argument for learning how to use this stuff. So in a pretty informal, and un-scientific way, I ran the following test:
-
// testing ternary operator vs. if/else
-
// just copy and paste onto the main timeline, and run
-
//
-
var loops:Number = 10000;
-
//
-
// ternary test
-
var startTime1:Number = getTimer();
-
for (var i:Number = 0; i < loops; i++) {
-
var testNum:Number = Math.floor(Math.random() * 100);
-
var isEven:Boolean = ((testNum % 2) == 0) ? true : false;
-
}
-
var endTime1:Number = getTimer();
-
var totalTime1:Number = endTime1 - startTime1;
-
//
-
// if/else test
-
var startTime2:Number = getTimer();
-
for (var i:Number = 0; i < loops; i++) {
-
var testNum:Number = Math.floor(Math.random() * 100);
-
if ((testNum % 2) == 0) {
-
var isEven:Boolean = true;
-
} else {
-
var isEven:Boolean = false;
-
}
-
}
-
var endTime2:Number = getTimer();
-
var totalTime2:Number = endTime2 - startTime2;
-
//
-
trace("Total Times: \n");
-
trace("\tTernary: " + totalTime1);
-
trace("\tif/else: " + totalTime2);
-
Running this test on my PowerMac with dual G5 2.0, and 1 GB ram, I came up with the following averages after running it 20-30 times: Ternary: 201 ms, if/else: 195 ms. Now, your results may vary, and this most likely isn't the best way to test something like this, but it's enough for me to see that there is a speed difference, but it's not enough of a difference to really make me stick to if/else exclusively.
The Google Calculator
by Josh on Jun.21, 2005, under Web

Everyone knows that Google is a great search tool, but did you know you can also use it as a calculator?
Try it: enter something like, "2 * 47", or "45 + 34 * (23 + 3)".
You can also use it to perform conversions - just enter what you got, into what you want: "25 miles in kilometers". Have you ever wanted to know how many miles are in one lightyear?
Great Flash FAQ - Good Refresher
by Josh on Apr.01, 2005, under Flash
While browsing through the ActionScript.org forums, Senocular responded to a post with a link to a Flash FAQ he'd posted on his site here.
While most of it may be old news to a lot you, there's a lot of good stuff in there that would be great for folks new to Flash to read, and it serves as a good refresher to those already experienced. One of those things where you read it, and it triggers that little voice in your head: "Oh yeah! I forgot about that!". One of those things. Makes a great reference for when someone asks you why their preloader doesn't start until 40, 53, or 72 percent for the umpteenth time.