Archive for June, 2008

The Best of Web Conferences 2008

Comments (1)

Common ActionScript 3 Errors and Explanations

So as with the new version of ActionScript there is a new level of complexity when it comes to creating ActionScript, but there seems to be better debugging too. The only barrier I have hit is the language sometimes just doesnt make sense, so I usually Google the errors and find great explanations.

This is just an ongoing list I will compile to help fellow AS3 developers to make sense of what the errors mean.

  • Error #1046: Type was not found or was not a compile-time constant:
    Curtis Morley has come up with a great explanation as to what this actually means, you can read about it here.
  • Error #1502: A script has executed for longer than the default timeout period of 15 seconds. Curtis Morley has also come up with another great explanation as to what this actually means, you can read about it here.
  • TypeError: Error #1009: Cannot access a property or method of a null object reference.Curtis Morley has also come up with another great explanation as to what this actually means, you can read about it here.

Comments

How to enable PHP in Mac OSX 10.5

I had read online that Mac OSX 10.5 now ships with PHP, but by default it is not enabled. I found a great article online which walks you through how to do so. Perfect for setting up a development environment.

Comments (2)

Part 2: Using LoaderInfo Events to create reusable ImageLoader Class

Yesterday I created a post called ActionScript 3.0 LoaderInfo Useful Events which outlined some useful events in ActionScript 3.0 that can be used to listen for when things are open, loading, and complete.

I used that knowledge to create a custom class which loads an image. I used events to listen for the opening of the the request, the download progress, and then the completion of the download. This is a basic class which can be applied to almost anything, although I kept it very basic for now. I plan to build upon this class over time until I have a reusable preloader class that I can apply to any project based off this code.

ImageLoader.as

Actionscript:
  1. package {
  2.     import flash.display.*;
  3.     import flash.text.*;
  4.     import flash.net.URLRequest;
  5.     import flash.events.*;
  6.    
  7.     public class LoaderExample extends Sprite {
  8.        
  9.         public var loaderStatus:TextField;
  10.        
  11.         public function LoaderExample() {
  12.             //Create the Loader and add it to the display list
  13.             var loader:Loader = new Loader();
  14.             addChild(loader);
  15.            
  16.             //Add the event handlers
  17.             loader.contentLoaderInfo.addEventListener(Event.OPEN, handleOpen);
  18.             loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress);
  19.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete);
  20.            
  21.             //Load the external image
  22.             loader.load( new URLRequest("image.jpg"))
  23.         }
  24.        
  25.         private function handleOpen (event:Event):void {
  26.             trace("open");
  27.             loaderStatus = new TextField();
  28.             addChild(loaderStatus);
  29.            
  30.             loaderStatus.x = 100;
  31.             loaderStatus.y = 100;
  32.             loaderStatus.text = "Loading: 0%";
  33.            
  34.         }
  35.        
  36.         private function handleProgress (event:ProgressEvent):void {
  37.             var percent:Number = event.bytesLoaded/event.bytesTotal * 100;
  38.             loaderStatus.text = "Loading:" + percent + "%";
  39.             loaderStatus.autoSize = TextFieldAutoSize.LEFT;
  40.             trace(percent)
  41.         }
  42.        
  43.         private function handleComplete(event:Event):void {
  44.             trace("complete");
  45.             removeChild(loaderStatus);
  46.             loaderStatus = null;
  47.         }
  48.     }
  49. }

To Instantiate this code, add the following code to the first frame of your flash file and make sure the class is saved in the same directory as the flash file.

Actionscript:
  1. import ImageLoader;
  2.  
  3. var images:LoaderExample = new LoaderExample();
  4. addChild(images);

Comments (1)

Part 1: ActionScript 3.0 LoaderInfo Useful Events

Im very impressed with ActionScript 3.0 and how all the events work. I have been reading up lately on progress events specifically the open, progress, and complete events. You can manipulate these events in so many ways, it makes creating a preloader a breeze. For example, you can use the progress event to create a listener that tracks the progress of a file that is being loaded into your flash file. You can accomplish this in about 3-5 lines, then you can create an Event.COMPLETE listener that checks to see when the file that you are loading is complete then it calls a function which does something. Its so much easier than having to create 10-15 lines of AS2.0 code to determine how much has been loaded, etc.

Useful Events:

  • open
  • progress
  • complete
  • init
  • httpStatus
  • ioError
  • securityError
  • unload

I will be working on a script/demo to explain this further, look for it in the coming weeks.

Comments