Posted: April 20th, 2008 | Author: John del Rosario | Filed under: AS 3.0 | Tags: ActionScript, AS2, AS3 | 1 Comment »
Just got back from a 4 day vacation. Now I have to continue my quest to scour the internet for everything ActionScript.
I found this site while reading a few things about tweening classes (I’ll have a post about that soon. I can’t believe I haven’t used them.). ActionScriptCheatSheet.com offers exactly what the title says, AS cheatsheets in PDF format. There are about 2 which are in JPEG format, which is a shame, but they are still useful.
They have cheatsheets for the Papervision 3D engine, Apollo specific ones, and AS2 to AS3 migration ones as well. Go to the DOWNLOADS page of the blog to choose your sheet of choice.
Posted: April 16th, 2008 | Author: John del Rosario | Filed under: AS 3.0, Learn, Programming and Development | Tags: ActionScript, AS3, Flash, Learn, Tutorials | No Comments »
I am in the process of converting from AS2 to AS3 right now, so I am going to try my best to post everything I learn in this blog. It might help others out there who are still also in the process of converting. To those who aren’t, you should.
This time it is about loading external images/swf’s.
In AS3, there are several types of DisplayObjects you could use to display on the stage (thus the name), along with MovieClips, Sprites(simple movieclips), Bitmaps(for bitmap data) and Loaders.
The Loader object is obviously what we would use to load these external visual data.
Basically, the Loader is just like a MovieClip, since they have a common superclass (well actually MovieClip is derived from Sprite, which is a sibling of Loader). It’s a like a MovieClip that could load objects. So, if you are coming from AS2, it would make things easier to think of it as just a MovieClip.
So, to load an image named “image.jpg”, first you need to create the Loader object. In the first frame of your timeline:
var loader:Loader = new Loader();
Now you need the url of the image to load it. The Loader object has a load() method that takes a URLRequest parameter. It’s just a class that handles url’s very well. Heh, I don’t really know much about it, you could read more of it in documentation.
var imageUrl:URLRequest = new URLRequest("image.jpg");
Now that we have our Loader object and our URLRequest, we could now load our image. It’s just simply calling the load() method of Loader and passing our URLRequest as argument.
loader.load(imageUrl);
addChild(loader);
After loading and adding it to the stage, you could do anything with it as you please.
loader.x = 50;
loader.alpha = .5;
Of course, you would want to have preloading for this kind of stuff. And yes, the Loader object generates similar events to the MovieClipLoader object we so loved in AS2. But all this happens very differently in AS3. All the information about the object being loaded is being held by a LoaderInfo object inside the Loader object.
So here is the code that traces the amount of kilobytes loaded adds the Loader object to the stage if loading is completed.
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loading(e:Event):void{
trace(loader.contentLoaderInfo.bytesLoaded);
}
function loadComplete(e:Event):void{
trace("loaded");
addChild(loader);
}
Hope this post helps others who are still starting to move to AS3. A lot has changed between the two, but AS3 is definitely the better one.
Posted: April 14th, 2008 | Author: John del Rosario | Filed under: AS 3.0, Flash, Learn | Tags: ActionScript, AS2, AS3, Flash, Learn, Tutorials | 4 Comments »
NOTE: This blog post is inaccurate. I am sorry for the error. I have fixed the error following the comments posted.
So in this blog, I’ll be posting things I learn each day (hopefully), about programming, life, etc. The things I post here might not be completely correct or true, but they are what I learned and I post them as I understand them. Corrections would be very much appreciated.
I’ll call it the [Learn] series.
NOTICE: I am telling this as how I understand it from reading other tutorials on the web. This is possibly very inaccurate, but maybe you could understand things you haven’t understood before by reading how I understand it. :-/
Event handling in AS3.0 is very different from AS2.0. One of my most used events is onEnterFrame events.
In AS2.0, animating a simple box to move to the right every frame would look like this:
(please bear with me and the unformatted code)
box.onEnterFrame = function(){
this._x += 1; //execute this code everytime the box movieclip enters a frame.
}
but in AS3.0, it is a little longer, and I may still have to see the real benefits of this. But already, I am liking how easy it is to understand.
function moveBox(e:Event):void{
e.target.x += 1;
}
box.addEventListener(Event.ENTER_FRAME, moveBox);
the addEventListener method tells the box MovieClip to execute the function moveBox, everytime an ENTER_FRAME event is generated(which is all the time).
Notice the moveBox function has an Event parameter. When a function has an Event type parameter, it becomes a listener function. Passing a non-listener function to the addEventListener method causes an error. You could also add the moveBox listener to any other MovieClip you might have on stage, already one of the benefits of the new event handling of AS3.0.
There are a lot more events to discuss, but I hope this helps those who have just started converting to AS3 (like me). I’ll keep on posting more things I learn.
Posted: March 26th, 2008 | Author: John del Rosario | Filed under: AS 3.0, Flash | Tags: ActionScript, AS2, AS3, Flash, Tutorials | No Comments »
I am currently reading a tutorial on AS3.0 with Flash CS3 by one of my favorite ActionScripters. I would love to learn it on Flex (the Flash interface sucks), but I just got too comfortable with using objects on stage as instances for the code on AS2.0. 
The great thing about this tutorial is that it has comparisons with how it used to be on AS2.0, and shows code on how it is on AS3.0. And so far it is very effective if you have a background in basic ActionScript. Coupled with a video tutorial from Lynda.com I ‘downloaded’, I think I could now completely switch to AS3.0!
I just love how similar it is to Java syntactically.
Here’s the tutorial: Getting started with AS3.0 with Flash CS3