AS3: Homegrown particles
First off, I will say that without Matthew Tretter’s garbage collection classes this demo would not be possible…While generating this many “particles” on ENTER_FRAME, the Flash Player can not keep up (or wouldn’t in my case), with the 3 tweens on X, Y, and alpha.
After saying that…here is a demo that I came up with tonight playing around in Flash and practicing some rapid development prototyping. It is a “particle” generator (that’s what I am calling it) using the display class, randomly positioning X and Y, as well as tweening the alpha channel.

Go ahead, click and drag below…you know you want to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import flash.display.MovieClip |
Related Articles:
AS3: Alternate row colors on dynamic movieclips
Below is an example of how to dynamically change the row color of generated movieclips. I find this helpfu when making grid based layouts, buttons, etc. You can have an unlimited amount of row colors by adding to the two if/then statements. Also, you can make this class re-usable by simply adding variables in the public function, passing them into the constructor method from your main fla movieclip instantiation. I try to keep all variables outside the main constructor, or at least in a single area, to help maintain the code and keep it cleaner.
Download the source project here

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | package com.riareviver{
//Flash Class imports
import flash.display.MovieClip |
Related Articles:
I am going to Adobe MAX 08
For the first time since MAX 2004 in New Orleans, I get to go this year in San Francisco. I have been to several, including back in the day when it was DEVCON, twice in Orlando. I am very excited and will be blogging about what I see. This year should be the best ever.
AS3: Floating Tool Tip using currentTarget
Without a lot of explanation on the topic, the following package creates 4 squares dynamically, then uses event listeners to point to global methods that checks the currentTarget. Based on mouse over or mouse out a method is called to show the tool tip (created on the fly) and changes its X and Y based on your mouse location. Basically, it is a floating tooltip demo, showing you how helpful currentTarget is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | package com.riareviver{
//Flash Class Imports
import flash.display.MovieClip |
Related Articles:
AS3: Using currentTarget to listen for your buttons
A lot of times when I am working on a project that has a lot of buttons, I like to simplify my event listeners into two methods, watching the currentTarget to see where to go. This is extremely helpful when you have to have a mouse down effect that needs to keep looping, say on a zoom. So, when the user holds the mouse down, I add an ENTER_FRAME event that keeps the event in a loop. By using currentTarget and a switch statement, you can keep your listeners set up nice and clean, also helps the next guy figure out what you are trying to accomplish…
1 2 3 4 5 6 | btnOne.addEventListener(MouseEvent.MOUSE_DOWN,checkMouseDown) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | function checkMouseDown(e:MouseEvent):void {
switch (e.currentTarget) {
case btnOne :
stage.addEventListener(Event.ENTER_FRAME,myMethod) |
Related Articles:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | package com.connatserdev{
//FLASH CLASS IMPORTS
import flash.display.MovieClip |
Next, we can start creating our re-usable classes, in this instance a class to create a simple box. You will notice in the setNewBox method, we are setting several variables. These values get passed as arguments from the document class, newBox.as. This is what helps make a class re-usable, meaning I can create as many children that I want in the document class by simple creating a new instance and pass these values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package com. connatserdev{
//FLASH CLASS IMPORTS
import flash.display.MovieClip |
Now all we need to do to use the class is add some actionscript to the constructor function in newBox.as, as follows:
1 2 3 4 5 | var boxOne:setNewBox = new setNewBox(20,100,100,20,0xCCCCCC,.5,0x000000, 0) |
Finally, here are our final .as files:
newBox.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package com.connatserdev{
//FLASH CLASS IMPORTS
import flash.display.MovieClip |
setNexBox.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package com.connatserdev{
//FLASH CLASS IMPORTS
import flash.display.MovieClip |
Related Articles:
Flash based facilities map
This week at KingPharm I created a Flash CS3 based facilities map for our intranet. This was built in AS3, using my super easy to use XML Feed class :). Each clip pulls meta data from an XML file that we can update when needed. I like working in XML and E4X with Flash because, if needed, we can add an AIR app later to administrate the XML file. Katherine Gibson did all the hard work in creating the actual vector based map, and I got to have all the fun in hooking it up to AS3.
Flash CS3: Easy to use 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) {
}
}
}Then we call in the needed classes, this goes above the class:
//Flash Class imports import flash.events.Eventimport flash.net.URLLoader import flash.net.URLRequest import flash.events.ProgressEvent import flash.display.MovieClip
Now we set up a couple of variables, one to instantiate an XML object, and one to set a load checking variable. We can use the public static var type so we can access the variables globally.
//Assigning the variables as public static lets us use them globally public static var fmapList:XML = new XML()public static var feedisLoaded:Number = 0
Finally we set up our function, creating the request, loader, and the loading the external XML file information into the newly formed XML object. I like to use a “loaded” method to let my parent document know that the feed is ready to be used, this example uses the Number variable: feedisLoaded.
//EVENT CALL var fmapURL:String = fmapURLvar fmapXMLURL:URLRequest var fmapLoader:URLLoader fmapList.ignoreWhite = true fmapXMLURL = new URLRequest(fmapURL) fmapLoader = new URLLoader(fmapXMLURL) fmapLoader.addEventListener(Event.COMPLETE,fmapLoaded) //Once the XML is loaded this method gets called to assign the loaded data to the XML object that we created //Also sets the feedisLoaded variable to 1, can be called in with an EnterFrame event. function fmapLoaded():void { fmapList = XML(fmapLoader.data) feedisLoaded = 1 } //
Now, here is the entire class that you can copy and paste to use. To use this class in your Flash project you will need to create a new variable (var myFeed:feedAggregator = new feedAggregator(”path to your xml file”); Then add that child (addChild(myFeed);)Then you can use feedAggregator.fmapList.* etc using E4X to call attributes in your XML file.
package com.connatserdev{
//Flash Class imports
import flash.events.Event
import flash.net.URLLoader
import flash.net.URLRequest
import flash.events.ProgressEvent
import flash.display.MovieClip
public class feedAggregator extends MovieClip {
//Assigning the variables as public static lets us use them globally
public static var fmapList:XML = new XML()
public static var feedisLoaded:Number = 0
//Collects argument for XML file path and begins the feed load
public function feedAggregator(fmapURL:String) {
//EVENT CALL
var fmapURL:String = fmapURL
var fmapXMLURL:URLRequest
var fmapLoader:URLLoader
fmapList.ignoreWhite = true
fmapXMLURL = new URLRequest(fmapURL)
fmapLoader = new URLLoader(fmapXMLURL)
fmapLoader.addEventListener(Event.COMPLETE,fmapLoaded)
//Once the XML is loaded this method gets called to assign the loaded data to the XML object that we created
//Also sets the feedisLoaded variable to 1, can be called in with an EnterFrame event.
function fmapLoaded():void {
fmapList = XML(fmapLoader.data)
feedisLoaded = 1
}
//
}
}
} You can also use the code block below in your document class to check to see if the feed is ready to use. This can let you use a simple loading animation until the value is = 1.
addEventListener(Event.ENTER_FRAME,traceFeed)function traceFeed(e:Event):void { switch (feedAggregator.feedisLoaded) { case 1 : removeEventListener(Event.ENTER_FRAME, traceFeed) break } }
Related Articles:
Flex 3: Populate a DataGrid with an ArrayCollection
In this tip I start off by creating a “initial load” method that creates the ArrayCollection that we will use to populate the datagrid. Be sure to set creationComplete=”methodName” within your application tag, or if using an MXML component your main tag. This tells the MXML document to call that method on completion of creating the page. You can use others like enterFrame, initialize, etc. as well.
Begin by setting the creationComplete event in the main tag to call the initData method.
1 2 3 4 | <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initData()"> |
Next, use the following block to create the ArrayCollection, as well as set the dataprovider for your datagrid:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <mx:Script> <




Interactive US Map
*Updated: Below is a new version of the US map for Zenith Fuel Systems. Next in line is a European version for their sister site.
I created a Flash based map of the US recently for a client needing to show distributors for each state. Click here to see the interactive version.






