Archive for the 'ActionScript 3' Category

21st May 2008

Flex Truveo Video Search

A few weeks ago someone contacted me about writing about the new APIs that AOL has made available. While looking at the AOL dev site I came accross the Truveo API and decided I would try creating a search application in Flex.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, Flex Comments No Comments »

14th May 2008

AS 3 Animated Clip Class

So recently I finished (as in have something usable, they’re never finished) an AS3 animation class.

Basically I client of mine had me use mc_tween.as for a few projects and I decide to have a go at creating something similar in AS3 (from what I have read on the author’s site, he to is working on an AS3 version).

If you want to check out the class, you can find it on google code. Again, all of this stuff is a work in progress, so bugs are par for the course.

Here is a quick sample of how it can be used. The following example is created using this code:

//ball is a movie clip whose class I have set in the linkage dialog to com.vfd.animation.AnimatedClip;
import fl.transitions.easing.*
ball.easing = Bounce.easeInOut
ball.fadeTo(0,2, true);
ball.sizeTo(10,10, 2, true);
ball.spinTo(90, 2, true)
ball.orbitDistance = 50;
ball.startOrbit();

UPDATE:

Also started an AS 2 version. In the same code repository on google code.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, OOP, Open Source Projects Comments No Comments »

29th Apr 2008

Setting the Initial Sort for a Flex DataGrid Component

A client asked me recently to to have the data being displayed in a Data Grid be initially sorted by store name (See Creating an Image Reflection in Flex to view the project in question). The way you do this is by sorting the Datagrid’s data provider. To do this, you need to create a sort object, assign it some sort fields, set that sort object as the dataprovider’s sort object (so you have to be using some sort of sortable collection to do it this way) and refresh the collection. This looks something like this:

private var storesXMLCollection:XMLListCollection = new XMLListCollection();
private var initSort:Sort = new Sort();

/ /SortField(name:String = null, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Boolean = false) so in this case companyName is the XML Node I am sorting on and the second parameter indicates that the sort should be case insensitive.

this.initSort.fields = [new SortField(“companyName”, true)];

this.storesXMLCollection.sort = this.initSort;

//once the sort object has been applied, refresh the collection.

this.storesXMLCollection.refresh();

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3, Flex Comments No Comments »

28th Apr 2008

Setting Up A Global Class Path In Flash

If you are just getting into using classes in Flash, chances are you are probably just creating your class (.as files) in the same directory as your FLA. This is simple, fast and works, but if I want to reuse a class from one Flash piece in another, I now have to copy over all of those class files into my new project directory. If I use that methodology, if I have to update something in one of my classes, I now have to update them in more than one location. This quickly turns into a maintenance nightmare and it turns out there is a simple solution.

Flash (as far back as mx 2007, not sure about older versions) will allow you to select a folder(s) where you can store classes that are used across multiple projects. This is commonly referred to as a class path. When you set up a class path and then do something like:


import com.mydomain.MyClass;
var myInstance:MyClass = new MyClass();

where MyClass is some custom class that you wrote, Flash will now look in your specified class path to see if it can find the corresponding class file (in this case MyClass.as). This means I am now free to use this class in any of my projects without having copy my class file into each project directory.

Please note that I am showing you how to set this for the program as a whole. You can also set this on a per document basis using the publishing settings

So how do we set this little piece of magic up?

  1. Got to the Edit menu and select Preferences.
  2. The following dialog box should appear:
    Flash Preferences
  3. Select ActionScript from the list on the left.
  4. Click the button entitled “ActionScript [version number] Settings” next to the Language label and the following dialog box should appear.
  5. Make sure to hit the + button resetting the entry that reads $(LocalData)/Classes will reset the default class path for Flash and Flash will no longer be able to find its built in classes. Clicking the + sign should make a blank line appear in the list.
  6. Click on the icon that looks like cross hair. This should bring up a file selection dialog box.
  7. Select the folder where you would like to store your classes.
  8. Keep clicking OK until all of the dialog boxes have closed.

Now you have your class path set up. This means that you can start storing you class files in this location. Please take note of the following:

  • Now that you have the class path set up, you can use import statements to bring in your classes just like you do with the standard Flash classes. For example import com.mydomain.MyClass; . Note a few things about the import statement.
    • The actual folder you selected is NOT included in the import statement (in my example C:\asclasses)
    • In import statements, dots = slashes. What I mean by this is that in our example, com.mydomain.MyClass is looking a file named MyClass.as in a folder mydomain that is a subfolder of com (i.e. /com/mydomain/MyClass.as). The beginning folder com in turn is actually a sub folder of the class path (i.e. C:\asclasses\com\mydomain\MyClass.as). Since we have setup C:\asclasses as a class path, Flash automatically looks in that location and we only have to specify the path using the dot syntax from that folder down. If you want to learn more about this dot syntax, do some research on the topic of packages in Flash.
    • As you may have noticed, you leave off the .as file extension.

Now that you have you class path set up, you can truly begin to start creating classes that are reusable across projects and only have to be maintained in one location.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 2, ActionScript 3, Flash, OOP Comments 2 Comments »

25th Apr 2008

Removing All Children From a DisplayObject

Just a quick one. The other day someone asked me about how to remove all sub clips from a movie clip in AS3. I happened to have created a function to do that for one of my projects.

private function removeAllChildren(displayObject:DisplayObjectContainer):void {
while (displayObject.numChildren > 0) {
displayObject.removeChildAt(0);
}
}

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 3 Comments No Comments »