Tweenlite: A Lightweight, Fast Tweening Engine

So it’s advertised.  Found it very simple to use.

1. Put movie clip on stage (for example, box).

2. Import the classes.  (import com.greensock.*)

3. Tweenlite.to(object_name,duration, {properties:change});

So the box would move from current position to (250,200, with alpha of 1)

with: Tweenlite.to(box,1, {x:250,y:200,alpha:1});

Will have to show a simple use case in the coming days.

Motion Trails and Lights

Two very good tutorials on ActiveTuts in terms of adding objects to the stage dynamically, moving them and then applying blurs, filters, and motion trails.  Though the titles seem completely different, the code underneath is basically the same.

Real Time Motion Trails

Whimsical Animated Background

SourceMate

I took the plunge and purchased SourceMate, a coding add-on to Flash Builder 4.  There are some simple features that really make coding much faster:

  1. creating value objects
  2. promoting local variables to fields
  3. auto-generating methods and classes
  4. code snippets

According to the tech support, there is no documentation and I had to wrap my head around the fact that you have to wait for an error before you get the option of creating a needed method or class, etc.  But I can accept it if it allows me to generate code faster and more efficiently.

The other thing nice about SourceMate is there are a number of features I have no idea what they are for.  These features clue me in to areas where I might want to do a little research.  They clearly are included because they saved someone else out there with their projects and perhaps I’m missing some cool tricks in my own projects.

I must say though I have been using FlashDevelop a bit more recently, and it is surprising similar to Flash Builder 4 with SourceMate.  I’d certainly recommend this free alternative if I was teaching programming.  Flash Builder 4 is free to students and educators, but SourceMate is not.

Bookmarks in Flash Builder and FlashDevelop

I haven’t had the need for bookmarks until recently.  The outlining feature of both Flash Builder 4 and FlashDevelop is very excellent, allowing you to jump to any method in your Actionscript file.

However, I have recently been consolidating my code.

I had separate methods called loadFeeds(), loadBlogs(), loadLinks(), loadMP3s(), loadVideos() etc.

I combined them into one function called loadItems(itemType:String) and had a switch statement to remove redundant code.  Now I had one method which was much longer, and the outlining feature no longer allowed me to jump to a particular method.

Adding bookmarks allows me to jump to the video section of the loadItems() method.

To add a Bookmark, click Edit–>Add Bookmark and give it a name.

In Flash Builder, you have to go to Other Views–>General–>Bookmarks to see your created Bookmarks.

FlashDevelop has Bookmarks view open by Default.

AS3Signals: Click Event

Creating a click event using AS3Signals is very convenient.

Within the class, create a public variable called clicked and set it as a NativeSignal();

Let’s say we have a Box.  When you click it, it should report back to the main document class.

public class Box extends Sprite
	{
 
		public var clicked:NativeSignal;
 
		public function Box()
		{
 
			graphics.beginFill(0x000000,1);
			graphics.drawRect(0,0,100,100);
			graphics.endFill();
 
			clicked = new NativeSignal(this,MouseEvent.CLICK,MouseEvent);
 
		}
        }

From the main class, create an event listener:

[codesyntax lang="actionscript3"]
 
package
{
	import control.Box;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
 
	/**
	 * ...
	 * @author M Skramstad
	 */
 
	public class SignalTest extends Sprite
	{
 
		private var box:Box;
 
		public function SignalTest():void {
		box = new Box();
 
		addChild(box);
		box.clicked.add(boxClicked);
 
		}
 
		private function boxClicked(e:MouseEvent):void
		{
			trace("box clicked");
		}
 
	}
 
}
package control
{
import flash.display.Sprite;
import flash.events.MouseEvent;

import org.osflash.signals.DeluxeSignal;
import org.osflash.signals.Signal;
import org.osflash.signals.events.GenericEvent;
import org.osflash.signals.natives.NativeSignal;

/**
* ...
* @author M Skramstad
*/
public class Box extends Sprite
{

public var opened:Signal;
public var clicked:NativeSignal;
public var closed:DeluxeSignal;

public function Box()
{

graphics.beginFill(0x000000,1);
graphics.drawRect(0,0,100,100);
graphics.endFill();

opened = new Signal();

closed = new DeluxeSignal(this);

clicked = new NativeSignal(this,MouseEvent.CLICK,MouseEvent);

}

public function open():void {
opened.dispatch("You opened the box",10);
}

public function close():void
{
closed.dispatch(new GenericEvent());
}

}

}

AS3Signals: A Better Solution to Events

I first took a look at AS3Signals when it first was being discussed, and I couldn’t get my head around it.  Mostly because I wasn’t that familiar with events at the time to see what it accomplished.  I heard about AS3Signals again through LA Flash, a user-group based around Flash in Los Angeles.

I took another look at AS3Signals and can finally see how it simplifies my code.  I started to modify the existing code and was able to remove the CustomEvent for loading data, remote the Event Dispatcher from the class, and eliminate some unnecessary code.

The following code calls a class called RemoteData which loads a list of feeds from an external database and returns it as a URLVariable when it is loaded.

private function loadFeeds():void {
	var l:RemoteData = new RemoteData();
	vars = new URLVariables();
	vars.action = "load feeds";
	l.load (vars,DB_LOC);
	l.loaded.add(showFeeds);
}
 
private function showFeeds(ld:URLVariables):void {
        var total:Number = ld.total;
}

In RemoteData, I only had to:

public var loaded:Signal = new Signal();
 
private function onItemsLoaded(event:Event):void {
	_loadedData = new URLVariables( _loader.data );
	loaded.dispatch(_loadedData);
}

Good tutorial (John Linquist.com) here:

and blog post (TK Assembled) about it here.

I would not be surprised if we see future iterations of ActionScript / Flash Builder incorporating such simplicity.

Snipplr: Code Snippet Repository

Snipplr is the Delicious of code snippets.  Share, post and comment on snippets from all programming languages.  ActiveTuts has a nice article: 15 Useful AS3 Snippets on Snipplr.

Certainly a good site for finding that piece of code to solve your programming issues, but the idea of posting more information into the cloud for comment and review does not appeal to me.  I have little interest in posting my code for review in this way.  I think if I wanted to store code online, I’d consider a GitHub type solution and pay a little.

Also, I prefer to store my content on my own website / server.  Do I trust putting more of my information in the hands of a company / service, when I have no clue whether this service will still be in business in two years?  I also think this service might want to join forces with Stack Overflow.

Dark Schemes for FlashDevelop

I’ve been trying to use FlashDevelop for some projects, to see how it compares and differs from Flash Builder 4.  I had to search a while to find some decent dark schemes.

The three I stumbled upon in my search were:

Latch Flog

Int3ractive

Trace Hello

and my own export (for AS3), probably a little too bright for most people.

Working with Arrays and Random Numbers

Trying to shuffle the items in an array, and I was having a heck of a time with a null variable. I was using Math.round(Math.random()*40), which was generating too large an array by 1.

I should have used:

Math.floor(Math.random()*40);

I also initially tried to copy an array with:

shuffled = itemsArray

but this association is problematic because when the array shuffled changes, so does itemsArray.

A good post about copying arrays in Actionscript 3 is here.  I used:

shuffled = itemsArray.concat();

This copies the contents of the array and therefore, doesn’t change itemsArray when you shuffle the array shuffled.

Loader Class in AS3

I think Republic of Code is a great site for tutorials on programming in Actionscript 3.0.

I was digging into the Loader class for dynamically loading in images. I had previously loaded them into a movie clip, but found this tutorial on using the Bitmap object a great assistance.