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.

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
[as]
package {
import flash.display.*;
import flash.text.*;
import flash.net.URLRequest;
import flash.events.*;

public class LoaderExample extends Sprite {

public var loaderStatus:TextField;

public function LoaderExample() {
//Create the Loader and add it to the display list
var loader:Loader = new Loader();
addChild(loader);

//Add the event handlers
loader.contentLoaderInfo.addEventListener(Event.OPEN, handleOpen);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete);

//Load the external image
loader.load( new URLRequest(“image.jpg”))
}

private function handleOpen (event:Event):void {
trace(“open”);
loaderStatus = new TextField();
addChild(loaderStatus);

loaderStatus.x = 100;
loaderStatus.y = 100;
loaderStatus.text = “Loading: 0%”;

}

private function handleProgress (event:ProgressEvent):void {
var percent:Number = event.bytesLoaded/event.bytesTotal * 100;
loaderStatus.text = “Loading:” + percent + “%”;
loaderStatus.autoSize = TextFieldAutoSize.LEFT;
trace(percent);
}

private function handleComplete(event:Event):void {
trace(“complete”);
removeChild(loaderStatus);
loaderStatus = null;
}
}
}
[/as]

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.

[as]
import ImageLoader;

var images:LoaderExample = new LoaderExample();
addChild(images);
[/as]

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.

Flash ActionScript 3.0 XML Basic Slideshow with Transitions

In this tutorial, Im building up what I started in the Text Array Loader. Basically, I have added the ability to pull in images and also setup the whole slideshow on a Timer event. So every 5 seconds (the time limit can be changed), the next image is loaded from the XML, and when it loads it uses an Alpha Tween from the TweenLite library to fade in. In the next version, I will be adding some sort of dynamic navigation.

Here is a screenshot of the XML File:

AS3 Part 1 Tutorial - XML File

This slideshow is based off my prior tutorial: Flash ActionScript 3.0 XML Text Array Loader.

Step 1: Declare Your Variables and Import Classes
This is where I first Import the gs.TweenLite class so that I can use it to tween my images. I also setup my variables here for my timer, my slide number, and my image loader.
[as]
import gs.TweenLite;

// variables
var xmlList:XMLList;
var slideNum:Number = 0;
var imgLoader:Loader = new Loader();
var slideTimer:Timer = new Timer(5000); //runs every 5 seconds
[/as]

Step 2: Load the XML
Now I setup the loader request for XML and once its finished loading using the EventListener, then I tell flash to pull the name attribute out of the first node in my xml file and I use the another instance of the loader class to to load the image out of the xml file. I then place the text in the dynamic text field called imageText and also add the first instance of imgLoader to the stage and tell it to tween in.
[as]
// load xml
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest(“images.xml”));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
xmlList = xml.children();
imageText.text = xml.image[slideNum].@name.toString();
imgLoader.load(new URLRequest(xml.image[slideNum].@src));
TweenLite.from(imgLoader, 1, {alpha:0});
imgLoader.x = 0 ;
imgLoader.y = 0;
}

);
[/as]

Step 3: Add Event Listeners
Now I setup the imgLoader event listener, that once that event is complete it will run onLoadComplete. I also setup the slideTimer here and start it. The slideTimer is set to call the function onSlideTimer every 5 seconds.

[as]
// stage event listeners
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
slideTimer.addEventListener(TimerEvent.TIMER, onSlideTimer);
slideTimer.start();
[/as]

Step 4: Change Text Function
I carried over the Change Text Function from my XML Text Array Tutorial and added a few lines to pull the next image from the XML file along with the next text description.
[as]
// this function will change the text depending upon which number is fed to the var slideNum in the onClickNextSlide function
function changeText(slideNum:Number):void {
imageText.text = xml.image[slideNum].@name.toString();
imgLoader.load(new URLRequest(xml.image[slideNum].@src));
addChild(imgLoader);
TweenLite.from(imgLoader, 1, {alpha:0});
imgLoader.x = 0;
imgLoader.y = 0;

}
changeText(0);

[/as]

Step 5: Timer Function
This is the most crucial part of the slideshow is what makes the slideshow run on its own. This is the timer function which the timer calls every 5 seconds. It will change the slide, so every five seconds its counts up a number and that is the image that is shown. Once it reaches the 5th image(4), it starts over at 0, which is really 1.
[as]
function onSlideTimer(evt:TimerEvent):void {
if (slideNum == 4) {
slideNum = 0;
}
else {
slideNum ;
}
changeText(slideNum);
trace(slideNum);
}
[/as]

Step 6: onLoadComplete Function
This function adds the imgLoader to the stage, without this you will not see anything in your movie. This is crucial!
[as]
function onLoadComplete(event:Event):void {
addChild(imgLoader);
}
[/as]

Im currently working on making this a tad more dynamic with buttons, and a slideLength variables which automatically changes the amount of slides so that you dont have to change the .fla file when adding more nodes to your slideshow. Im also going to be working on getting slicker transitions working such as images that slide in/slide out off the screen.

Here is an example of the working file:
View Demo

Download all the source files here: AS3 Basic Slideshow with Transitions (6123)

ve ringtones motorola for alltelwireless ringtones alltel alltell 41 1 417 free top ringtonefree ringtones 1260ringtone 190 motorola download1st ringtoneringtones 2285mp3 ringtone 6230 Mapfree sex movie slavemovies preteenmovies musclemen samplealien movies ant farmadult movies free samplesex movies freelesbo movieshome wifes movies Mapmovies porn free bigfree lactating moviesmovies free milfhunter downloadedgallery movie shemale freewindows maker free moviethe holes movie soundtrackhorror movie figures actionnude jennifer movie connelly Mapalaska loan supplementalloans alliedstudent american loanprivate student aarp loansloan abn mortgage resolutionloan unsecured $500,000personal ameriquest loansfederal stafford a-subsidized loans Mapbabysitters pornsporn party bachelor nightporn breakin backfacial room back pornporn for access backdoorbackdoor porn sitesbackroom pornporn bangers site backyard Maptottaly spies pornfree view clips pornxxx free rated pornringtone walsh joe wavhop ringtones hip midi 10kb3 ringtonesnokia 3520 ringtone 3560 freenokia 5125 ringtone free download MapAsian TGP speculumMujeres eroticasLatina Mollig TGPpusy – ATK BehaarteBiw interrassischGranny Interrassischpissing LollitaErotik Sapphic Sandy Map

Flash ActionScript 3.0 XML Text Array Loader

After creating the Flash 8 ActionScript 2.0 Image slideshow modifications, I wanted to start from scratch on my next set of tutorials with AS3. AS3 is very different from AS2, the learning curve is not easy but its worth it. I would like to recommend a few books to help you get started in AS3; Essential ActionScript 3.0 by Colin Moock and Learning ActionScript 3.0: A Beginners Guide by Rich Shupe and Zevan Rosser. This is my first tutorial in a series where I will be rebuilding the XML/Flash Slideshow in ActionScript 3.0.In this tutorial, I will be focusing on how to setup your XML file, how to read in text from that XML file into you flash, and how to move through the xml nodes in your flash file and have them show up.First thing is first, how do you setup your XML file, I used a lot of examples from Colin Moock’s book to achieve this. By no way is my way the right way, since XML is pretty flexible. I setup my xml file by opening up with a parent node “images” then placing all of the attributes within each node “image”. AS3 makes it really easy to pull the varibles out, so thats why I set it up this way. Here is a screenshot:

AS3 Part 1 Tutorial - XML File

Next, I setup my AS3 file. I opened a new AS3 document, and created two movieclips and gave them instance names of prevBtn and nextBtn. I didnt setup my code in OOP, that will be part of the next tutorial. I just wanted to do something basic here to help people get started. I also added a dynamic text field to the stage and gave it an instance name of “imageText”.

Step 1: Declare Your VariablesThis is where I setup my Loader and XMLList instances. I also setup slideNum which Im going to be using to hold the position or index of the array.

[as]
//variables
var xmlList:XMLList;
var mcLoader:Loader;
var slideNum:Number = 0;
[/as]

Step 2: Load the XMLNow I setup the loader request for XML and once its finished loading using the EventListener, then I tell flash to pull the name attribute out of the first node in my xml file and place it in the dynamic text field called imageText.

[as]//loads xml and assigns the text field the first node using the slideNum variable from above
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest(“images.xml”));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
xmlList = xml.children();
trace(xmlList);
imageText.text = xml.image[slideNum].@name.toString();
}
);[/as]Step 3: Add Event ListenersNow Im telling flash that whenever a user clicks to perform a function. So if a user clicks on nextBtn, the onClickNextSlide function will run. If a user clicks on prevBtn, the onClickPrevSlide function will run. This is one of the biggest changes of AS3, whenever you create a button, you must always assign it an event listener. There seems to be much more flexility in this way.[as]
//stage event listeners for the movieClip buttons
nextBtn.addEventListener(MouseEvent.CLICK, onClickNextSlide);
prevBtn.addEventListener(MouseEvent.CLICK, onClickPrevSlide);
[/as]Step 4: Change Text FunctionThis function works with the buttons. The text will change based on the slideNum var that is fed into the function from the button functions which come next
[as]
//this function will change the text depending upon which number is fed to the var slideNum in the onClickNextSlide function
function changeText(slideNum:Number):void {
imageText.text = xml.image[slideNum].@name.toString();
}
changeText(0);
[/as]
Step 5: Button FunctionsThe onClickNextSlide function increases the slideNum variable with each click. If slideNum reaches 4 (the total number of nodes), then it starts over at 0. The onClickPrevSlide function does the reverse.[as]
//this function adds 1 to the current number, if the current number is 4, it starts over
function onClickNextSlide(event:MouseEvent):void {
slideNum++;
trace(slideNum);
if (slideNum == 4) {
slideNum = 0;
}
changeText(slideNum);}
// this function dos the opposite of the one above, it subtracts 1 to current number, when it reaches 0 it starts back at 4
function onClickPrevSlide(event:MouseEvent):void {
slideNum–;
trace(slideNum);
if (slideNum == 0) {
slideNum = 4;
}
changeText(slideNum);}
[/as]

There is currently some known issues which Im going to fix and re-release. I know currently that if you try to go backwards when the flash first loads, it wont work. The previous button only works after you go forward first. If anyone has a solution, please post a comment. Here is an example of the working file:View Demo