Flash CS3 / Flex 2 Error #1502:

Error #1502: A script has executed for longer than the default timeout period of 15 seconds.

Problem:
You have entered the realm of “Flash Infinite Loop” or at least a really long loop. This is very common when running loops, especially do…while loops.  The timeout is now set to 15 seconds (see image below).

ActionScript Error 1502

Fix:
Make sure that you are not executing a loop that will never break out. Those poor loops running in circles for all of us Flashers/Flexers.

*******************Warning*******************
The Bad Code below will send your Flex/Flash into and infinite loop and will potentially crash your Development Tool. DO NOT COPY and PASTE the BAD CODE EXAMPLES BELOW.

Bad Code:
var myLength:int = 2;

for (var i:int = 0; i < myLength ; i–);
trace(i);
}

Good Code:
var myLength:int = 2;

for (var i:int = 0; i < myLength ; i++);
trace(i);
}

The code examples above have the var i starting with a number that is smaller than the number it is trying to iterate to. This code basically says as long as i is smaller than myLength then loop and each time I loop make i even smaller.

Bad Code:
*********This code crashed my Flash multiple times.*******

var myArray:Array = [“joe”, “bob”,”pam”];
var randNum:int = Math.round(Math.random()*myArray.length-1);
var curNum:int = 1;
do {
trace(randNum);
} while (randNum == curNum);

The key to using do…while loops in Flash is to make sure that the variable that you are validating against is changed inside the loop itself. Unless the variable that you are validating against changes within the loop itself it will loop forever. This example of a do…while loop is valid but will very likely put Flash into an infinite loop because the likelihood that the number will be 1 is very high, especially considering that the code is rounding and the number 1 is the middle digit of the three. This loop can execute quickly if Flash happens to choose another number or it can loop infinitely. The reason you might be doing this kind of loop is because you want to pull things out of an array, xml, or some other list and don’t want to get duplicates. A better way to do this is to either use the splice() methods in Flash or Flex or if you don’t want to affect the original array you can slice() out a duplicate without the curNum value and then the value will never be repeated because it no longer exists in the items that you are evaluating against. That way you know for sure the item that you don’t want repeated is gone.

There are many other ways to run into an infinite loop. These are just a couple. Feel free to post any questions you have in the comments section and I will answer them promptly.

Thanks and Happy Flashing.

Flash CS3 / Flex 2 AS3 Error #1119

Error #1119:
Access of possibly undefined property buttonText through a reference with static type flash.display:SimpleButton

or

Error #1119: Access of possibly undefined property someProperty through a reference with static type flash.display:DisplayObject.

Description:
This means that you are trying to change dynamic text nested inside a button. This is a simple fix. Just change the button to a movieClip.

Another more prevalent reason that you will get ActionScript Error #1119 is because the the new way Flash/flex handles parent objects has changed. In AS2 parent.myVar would work just fine. In ActionScript3 the compiler doesn’t know what the parent is unless specifically typed or casted instead it chalks everything up to DisplayObjectContainer. This means that it doesn’t know that the ‘parent’ is a MovieClip. The reason for this is because you can now change the object from one displayObject to another easily at compile time. You could change the parent object from a MovieClip to SimpleButton at compile time.

You also want to check your syntax to make sure that you have dynamically targeted an object correctly. For example, if you are trying to use AS3 to target a series of movieClips dynamically and each of the names start with ‘card’ and have a sequential value as well then you must use the code in Fix3 to prevent AS3 Error #1119. Fix #4 is similar to Fix 3 but Fix 4 is specific to the DisplayObject.
Fix 1:
You need to cast the parent as the type that you want or you need.

myTextField.text = MovieClip(this.parent).someVar
or
myTextField.text = (this.parent as MovieClip).someVar

One of the best explanations of casting for this error is written up by Josh Tynjala go visit his blog called “Why doesn’t the ‘parent’ property work the same in ActionScript 3”

.

Fix 2:
Rather than looking outside the movie for the variable you can push the variable into the child movieClip and then access it within itself. For example if I have a movieClip named bob that is inside of a clip named joe then I would have Joe push the variable into bob and bob would access it within himself and not need to ask his parent for the variable because he already has it.

From Joe

bob.someVar = “This is the variable”;

From Bob

myTextField.text = someVar;

Fix 3:

Bad Code:

this.card[i].id = “something”;

Good Code:

this[“card”+i].id = “something;

Fix 4:
The good code below uses a direct reference to the object that holds the property someProperty. Whereas the Bad Code example is trying to access the property through a reference through the displayObject. Because the displayObject doesn’t have the property it cannot change it.

Bad Code:

this.getChildByName(‘card’+_setClicksCounter).someProperty = true;

Good Code:

this[“card”+_setClicksCounter].someProperty = true;

Fix 5:
1119: Access of possibly undefined property nestedMovieClip through a reference with static type Class.
This is easy to fix. It just means that you are trying to access a nested object within the class statement rather than from within the Class. The problem is that the keyword “this” in the first example doesn’t references the Class itself rather the object the Class is linked to.

Bad Code:

package com.cjm.sound
{
public class SoundControl extends MovieClip
{
var _progwidth:uint = this.progBar.width;
public function SoundControl (url=null):void
{
doSomething();
}}}

Good Code:

package com.cjm.sound
{
import flash.display.MovieClip;
public class SoundControl extends MovieClip
{
var _progwidth:uint;
public function SoundControl ():void
{
_progwidth = this.progBar.width;
}}}

Related Errors:
Flash / Flex Error 1056 – You will get AS3 Error 1056 instead of 1119 if you don’t properly type your object before referencing a property on it. For example var s:Sprite = new Sprite(); s._x = 10; will give error 1119 but var s = new Sprite(); s._x = 10; will give Error 1056.

As always – Happy Flashing

Speaking today at BYU on Flash & Google Analytics

Today I will be a guest speaker at BYU and will be talking about Google Analytics in Flash. I will be showing the students the power of using analytics and Flash. I will also be talking briefly about Omniture analytics and Flash. My talk will be centered around the capabilities of fine tuned tracking with Flash and what data should be tracked. I will also talk about the class that I am about to release that is built for Google Analytics and Flash.

Stay tuned and Happy Flashing.

Effective way to Test Dynamic Data from Server and in Flash Authoring Tool

Say you have a Flash widget that you need to put on the server to receive dynamic data yet you want to test it in Flash with all of your nice trace(); statements etc… The only trouble is that when you post it to the server you always forget to comment out the values that you test with. These are the hard coded values you typed into the file or Class. You don’t want to have to remember each time you FTP the file up to the server to comment out those pesky variables that are critical for testing in the Flash authoring tool.

The solution to the problem is quite simple. All you need to do is ask Flash where it lives. You do this by having Flash ask what is its URL using this._url

Here is the code:

if (this._url.substr(0,5) == "file:")
{
var fillBytes:Number=978;
var totalBytes:Number=2712;
}

Here is the explanation:

  1. Setup a conditional statement - if()
  2. Because anything run in Flash will be located at a file path, ask if the location(_url) name starts with the characters "file:" - this._url.substr(0,5) == "file:"
  3. If the answer is yes then set your variables - var totalBytes:Number = 2712

A web address will never start with the characters "file:" but rather "http" or the name of a subdomain. Because of this the variables will not yet be defined when the file is on the server and your .swf will be ready to receive anything the server has to throw at it. And yet, you will always be able to test it in the Flash authoring environment.

Happy Flashing

Google Analytics and Flash

I am putting up a test experiment for a Flash class that I built that will add a lot of functionality to the Google Analytics. Please help me test out my class by simply playing with the Flash objects below. Mouse over them click on them, just leave your mouse alone and do nothing at all.

The purpose of this Flash and Google Analytics experiment is to get more granular data about how the user interacts with the Flash object. The class I’ve created will tell me how long it takes people before they interact with the piece, how long they are interacting with it, how many times the user mouses-over, clicks, etc…

Thanks for the help in testing this. I will post results next week.

Floating Planes

The Greatest Mozilla Firefox Extension Ever.

So I was surfing the other day and I came across a Mozilla Add-on that is fantastic. This Firefox Extension is a huge time saver and an amazingly wonderful tool for any Flash Developers out there.

Of course this Firefox extension was built by Alessandro Crugnola of Sephiroth. It takes a someone like Alessandro to make such a useful tool.

Download Flash Switcher here. http://www.sephiroth.it/weblog/archives/2006/10/flash_switcher_for_firefox.php
For those of you not familiar with how extensions work you will want to download the extension (.xpi file). Open it from the download window and then when the download window asks what program to open it with find Firefox.

This should bring up a window like this:

Install Flash Switcher

Click “Install Now” and then after you restart look for it down in the corner of the browser.

This Firefox Extension is a must for any serious Flash Developer
Happy Flashing with all versions of the Flash Plugin

P.S. My second favorite extension is the myStickies

My drop down menus are behind my Flash

Have you loaded up a Flash file and now your drop down menus are all a mess because they go behind your Flash instead of on top? Did you try changing the zIndex of your iFrame or try to put iFrames behind the menu to push it to the top? Does your drop down menu look like this?
wmodeBehind
But you wish it would look like this.
No wmode = transparent property
Well forget all the iFrame business and and feel relieved because all that is neccessary is to simply include the wmode parameter in your HTML. All you need is a little love and a simple tag and you should be fine.

To get started you should be using either swfObject or the Adobe AC_RunActiveContent.js to embed your Flash. I highly suggest the swfObject Flash Detection scripts because of how complete it is. swfObject combines Active content activation, Flash detection, Flash Express Install, and is search engine friendly.

Below you will find the wmode code for each method so that you can have menu systems like everyone else on the web.

Code – swfObject var so = new SWFObject("myFlashMovie.swf", "mymovie", "200", "100%", "7", "#336699");

so.addParam("wmode", "transparent");
so.addParam("salign", "t");
so.write("flashcontent");

Code – AC_RunActiveContent.js- AC_FL_RunContent(‘codebase’,’http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0′,’width’,’550′,’height’,’400′,’align’,’middle’,’src’,’myFlashMovie’,’quality’,’high’,’name’,’myFlashMovie’,’pluginspage’,’http://www.macromedia.com/go/getflashplayer’,’movie’,’myFlashMovie’,’wmode’,’transparent’);

Make sure that you have an even number of parameters with the example above or it will break it.Other links about the issue:

Stephanie Sullivan article on Community MX

Interakt Online Article
http://menumachine.com/kb/65
http://www.actionscript.org/forums/archive/index.php3/t-101350.html

Don’t let your Flash files get corrupted

Today on slashdot an article that all of us Flashers, Photogs, and Designers should be aware of. One of the recent updates from Microsoft will corrupt files that are in the .swf and .jpg format.

Slashdot says, “If you have compression activated on any folder, then the compressed data is at risk from corruption.”

Microsoft has been alerted that “KB920958 causes data loss on compressed folders in Windows Update

The files that are at risk are reported to be:
.JPG
.GIF
.SWF

Good luck and make sure to turn off compression.

General Windows-

Windows XP — Right Click on the “C” drive > Under the “General Tab” make sure the Check box at the bottom that says “Compress drive to save disk space” is unchecked.

Individual Folders — Right Click on the folder > Click on “Properties” at the end of the list > On the “General” tab click on the “Advanced” button >Make sure the check box at the bottom that says “Compress contents to save disk space” is unchecked

Flash SEO

So the other day I had an interesting conversation with Parker Garlitz of Patrick Henry & Associates, a noted Search Engine Optimization (SEO) expert and 2-time Dungeons & Dragons champion. The discussion was something like this –

“The best thing you can do for www.directpointe.com is take off all Flash from your site. This is going to sound crazy but you need to ‘uglify’ your site to get people to conversion.” Patrick said. “Flash is the worst thing you can do to your site if you want search engines to find it.”

He was very adamant about the fact that Macromedia Flash can not be crawled by search engines. Because I challenged him on this fact, he said tell me one site that uses Flash extensively and ranks on search engines.

So, I decided to take him up on the offer. Here are my findings.
I searched out what the most searched keywords are. I went with the results from Google, Yahoo, and AOL. I typed these into the search engines and this is what I came up with. This list was gathered on 8/22/06.

Websites that show up on page one of Google and use Flash extensively.

Search Term – Sports
www.ESPN.com
msn.foxsports.com

Search Term – Tour de France
www.bicycling.com

Search Term – World Cup
www.fifa.com

Search Term – Talk Show
tyrashow.warnerbros.com

Search Term – NASCAR
msn.foxsports.com/nascar

Search Term – Computer
www.gateway.com

Search Term – Music
www.mtv.com

Search Term – News
www.usatoday.com

Search Term – NFL
sports.espn.go.com/nfl/index
msn.foxsports.com/nfl
sportsillustrated.cnn.com/football/nfl/specials/preview/2006

Search Term – Pizza
www.pizzahut.com
www.dominos.com
www.cpk.com

Other notable sites that use Flash extensively

www.oprah.com

www.disney.com

mythbusters

video.google.com

www.youtube.com

www.flickr.com

www.myspace.com

www.homestarrunner.com

www.newzealand.com/travel

Nordstroms

Canadian National Budget

Zions Bank – Promotion

Zions Bank – Microsite

AMD

Even Walmart has gotten into the act.

Most car manufacturer, fashion designers, sports teams, movie websites, airlines, computer makers, cell phone companies, universities, governments, etc… etc…. etc… use Macromedia Flash extensively. That seems like a lot of smart people to me. There must be a reason for using Flash to get people to conversion. The fact is that Flash can be crawled and flash elements can be effective. The days of Flash being invisible to Google and the gang are over.

Stay tuned for the next blog on how to Optimize Flash the right way for SEO and the results of making www.DirectPointe.com compelling, effective, viral, and searchable.