AS3: Learn how to create a re-usable Class
AS3: Learn how to create a re-usable class
Download an entire Flash project using this example here.
One thing that I found hard, being a designer turn developer turn pseudo programmer, was understanding how packages, classes, and overall re-usable code is handled. Once it clicked with me then I was off and running, but every example that I found was so complex or a small part of a larger project. What I am presenting below is a simple walk through of how to create a very simple package, and use it passing arguments.
You will need 3 files, newBox.fla, newBox.as, and setNewBox.as. Feel free to use any name for this, but it will be easier to follow along if you name them as I have. To start off, set your document class in the newBox.fla file. I have named my document class newBox.as. That is all you need to do in the .fla, no “frame coding” going on here…
Our constructor function, or the function that gets called in when you assign a document class…is then created as follows:
package com.connatserdev{ //FLASH CLASS IMPORTS import flash.display.MovieClip; //CUSTOM CLASS IMPORT import com. connatserdev.setNewBox; public class newBox extends MovieClip { public function newBox() { } } }
AS3: Simple XML Feed Class
This tip will help you create an easy to use, re-usable class that will set up an external XML feed to use E4X, datagrids, etc. I didn’t change any variable names from my working code, so feel free to change them as needed as the variable names don’t relate to any particular thing…
Download an entire Flash Project using this class here.
To start off we create our package, using my domain name for example, but change this as needed:
package com.connatserdev{ public class feedAggregator extends MovieClip { //Collects argument for XML file path and begins the feed load public function feedAggregator(fmapURL:String) { } } }
AS3: Motion Blurring with Flash, part 2
To build more on the motion blur in AS3 tip, I am breaking the code out in more of a OOP structure. I use FDT3 extensively to create my AS3 projects, so this tip will be more focused on usind FDT3 for the code with minimal Flash CS4 setup.
For this tip you will need basically one Flash file and one .as file, named FilterBlur.as. If you are using FDT3 you will need to compile a .swc to access the fl.transitions classes, or download it here – http://apdevblog.com/update-using-flvideo-package-w-eclipse-and-fdt3/. Then you will need to link the .swc as a “linked library”.
The Flash file will be fairly simple, just the stage and one movie clip, in my case a blue rectangle. When creating the movie clip make sure you check the “Export for ActionScript” box, and set the Base Class as “FilterBlur”. This links the FilterBlur.as class directly to the movieclip instance, letting you use “this” in the .as file. After you set this up, any action within the class that refers to “this” will affect the movieclip instance. That’s it on the Flash side, now on to the FilterBlur.as class.
In the same directory that you create the Flash file, the name of the Flash file doesn’t matter, create a new ActionScript 3.0 class name “FilterBlur.as”. If you put this in a different directory, such as “com.blah.blah”, just make sure your path within the movieclip refers to the same location.
Click on the rectangle below to see a demo of the blur effect.
AS3: Motion Blurring with Flash, part 1
The other day I needed to help out a co-worker and create some menu animation in Flash CS3. To set the stage, there are 4 bars that come out from left to right, each in a slightly different default position and each needed independent characteristics. After setting up the initial project, creating the buttons, etc. I began the AS3 code needed to move the bars. To simplify the article I am just using one bar. In my project I am calling a method containing conditionals (if/then) to determine whether the button stays or not. My full code example will be given later.
To move a instance of a movieclip in AS3 you will need to call the following classes:
import fl.transitions.*; import fl.transitions.Tween; import fl.transitions.easing.*;
Then create a listener to call the method, which is a bit of code created give a button access to method. A listener defines the event for which to call the method (function) that contains the code we want to run. In this case I am using a MouseEvent event with a value of MOUSE_OVER, which is case sensitive. mainBtn01 corresponds to the instance name of the button, btnBaropen corresponds to the method name that we are calling.
mainBtn01.addEventListener(MouseEvent.MOUSE_OVER, btnBaropen);
To start moving the button we will need to set a Tween variable:
var btnTween:Tween;

Recent Comments
GarthDB on FlashBuilder: SourceMate AS3Signals Template:
Thanks Brian. I appreciate this being here....
kathryn on I have joined litl!:
psyched to have you onboard! this team just gets more and more awesome....
Filippo on My FlashBuilder 4 color scheme.:
Flash Builder is such a powerful tool, but syntax highlighting just sucks! ...
Devi on AS3: Creating custom events:
This example is awesome...
Josh Molina on AS3: Creating custom events:
Excellent tutorial. Straight and to the point.Thank you.Jo...