Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, viagra 60mg the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.

Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, viagra 60mg the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.

Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, clinic the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, dosage you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, information pills did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.
Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, viagra 60mg the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.

Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, clinic the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, dosage you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, information pills did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.
Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, information pills the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, ailment you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, visit this site did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.

Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, buy more about medications the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.

Ranch Dressing

I have never liked the stuff in the green and white bottles labeled as Ranch Dressing. You have to question a substance that does not rinse off the plate easily. If it has to be scrubbed off a surface I can’t imagine what it is doing to the inside the body.

We switched to an organic ranch dressing without the chemicals and soy, buy more about medications the way nature intended- with real food. I had to drive 30 minutes to the only store around that carried it. Needless to say the family had to endure eating their veggies without it. I was looking at the bottle one day and thought, you know I can make this stuff. It is only some herbs and buttermilk. How hard can it be?

Several recipes later… the only part I do not like is the addition of mayo. I tried making it with all yogurt and some lemon juice. That did not end so well. I also wanted to use ingredients that I will almost always have on hand. Based on that criteria alone the use of buttermilk was ruled out. Chef John’s recipe was a unanimous hit with the kids. Dad and I however, did not like that it had too much mayo flavor. I cut out a couple tablespoons but ideally I like to use use 1/3 cup mayo and 1 1/4 cup greek yogurt. I dislike using the mayo but I have yet to figure out how to replace the flavor it lends.

If you are looking for a good homemade recipe to wean the kids on then this is a good start. Normally I use the variations listed below- milk and vinegar vs buttermilk, oregano in place of the dried and fresh herbs. It is what I have on hand. Once I master the mayo problem I will list it under variations.

Source: adapted from Chef John
1/3 cup plain greek yogurt or sour cream
1 1/4 cup mayonnaise
1/2 teaspoon garlic powder
1/2 teaspoon onion powder
1 tablespoon minced fresh Italian parsley
2 teaspoons sliced fresh chives
1/4 teaspoon dried tarragon
1 pinch cayenne pepper
1/4 teaspoon ground pepper
1/8 teaspoon salt
1/3 cup buttermilk

Mix all ingredients together in bowl. Serve with cold fresh vegetables, or thin out dip with a few splashes of buttermilk to make ranch dressing.

Tip: for thicker dip reduce the amount of buttermilk slightly.

yield: 1 1/2 cups

Variations:
– I prefer 1/3 cup mayo to 1 1/4 cup greek yogurt.
– If using real onion use 1/4 cup minced.
– If you do not have parsley, chives and tarragon, sub a teaspoon dried oregano.
– Replace buttermilk with 1 teaspoon white vinegar and enough milk to make 1/3 cup.
http://www.chow.com/recipes/29184-ginger-chicken-jook-rice-porridge

6 cups water
4 cups low-sodium chicken broth
1 1/2 pounds bone-in chicken legs or thighs, page skin removed and trimmed of excess fat
1 cup long-grain white rice
1 (1-inch) piece fresh ginger, skin on and sliced into 4 pieces
2 teaspoons kosher salt, plus more as needed
Pinch freshly ground white pepper, plus more as needed
Coarsely chopped fresh cilantro, for garnish
Thinly sliced scallions, for garnish
INSTRUCTIONS
Place all ingredients except the cilantro and scallions in a large heavy-bottomed saucepan or Dutch oven and bring to a boil over medium-high heat. Reduce the heat to medium low and cook at a lively simmer, stirring occasionally, until the rice has completely broken down and the mixture is creamy, about 1 hour.
Turn off the heat and remove the chicken to a cutting board. When it’s cool enough to handle, shred the chicken into bite-sized pieces, discarding the cartilage and bones. Return the chicken shreds to the jook. Stir to combine, taste, and season with additional salt and pepper as needed. Ladle into bowls and top with cilantro and scallions.
Welcome to my blog. It is pretty weird that I have been involved in building blogs and social network type sites for clients, clinic yet I only now getting around to posting something online for my self. The web has been a great source of learning for me over the last few years and thought it was time to give something back.

 I have a few posts already planned out, cialis 40mg most are Flash tips and tricks, ailment and a few already in the works. Most of the flash tips are based on my experiences as a designer learning AS3, then I would like to share some other classes and older AS2 stuff. So stay tuned and in the mean time go build some cool stuff.  

If you would like to see some samples of past projects I have worked on, check out www.hdinteractive.com .
As a UX Designer/Developer that believes our relationship with technology can be inclusive, cheap website side effects productive and delightful, viagra I wanted to build a site where all my inspirations come together in one place.

This Blog was put together to reduce the amount of effort required to keep up with the latest news and information about user experience, order gaming, mixed reality, and similar forms of immersive technology.

All the original sources of these articles are listed in the blog roll.
There’s also a twitter feed containing many of these sources.
Immersive UX Twitter List

I also hope that this collection could have some value to a community of fellow UX designers and the many online mentors I’ve found over the years. I have literally learned everything I know through online research and a great deal of trial and error, experimentation if you will, over many years. So many you provide blog posts, tutorials and other scraps of knowledge that has helped me through almost every design and development challenge and I am continually inspired by many of you that share your knowledge and experiences with the rest of us. Thank You!

What happened to _global, this site cost and _root, _level?

(Working With and Building Custom Events)

I rarely used _root or _level just because some projects would end up getting loaded into other swfs. Sometimes I didn’t know this until halfway through or in the end. So I started using global instead. That way I could still target the main timeline, which is where I would try to keep all my code, without having to worry about root moving somewhere else later. When I built components I would also use global, from time to time, to target them from anywhere in the application being developed.

The best workaround I have come across on the web for storing global variables, is to create a class object and throw all your variables in there. Some great information about this can be found here: http://www.uza.lt/codex/as3-global-object/

A brief simple example is something like this:

package {
public class global{
public static var Vars:Object = new Object();
public static var Arrs:Object = new Object();
public static var _locked:Boolean;

public function global(){

}
}
}


Notes: If you want to store dynamic variables (ones that are not predefined in the global Class) then you will need to send them to the Object Vars or Arrs (global.Vars.newVariable = “yo!”). Adding and updating arrays can be a little tricky, but I will write a lot more about this in the future. I am working on a watch/listener Class for AS3 that uses some of this functionality.

Like I mentioned earlier, it works great for variables, but not so much for global functions, which is what I used global for the most.


So Let the Griping Begin:

I know it is 3:00 am and you have deadlines. Now is not the time to re-think how to build your application. What in the world was Adobe thinking with AS3 anyway. Flash is a designers/animators tool to build pretty applications right? How in the world do they expect designers to learn this stuff. It took years to get the hang of AS2, now it feels like they have pulled the rug out from underneath us. Plus, now that programmers are the only ones able to program in Flash, expect a bunch of new Flash sites full of ugly stuff that moves.

Before I get too carried away, we should realize things aren’t so bad. Actually they are pretty good.

[ad#content_banner]


The Real Answer : Events

AS3 is much more of an Object Oriented Programming(OOP)d language then AS2. We can work around that fact, or we can embrace it. In an OOP mindset, we have to think of our project as made from objects (duh) that are children or siblings of other objects and communicate with each other using events. The new event and child systems are really powerful, it just takes a little getting used to.

When we have multiple objects that need to pass information to a central location, and parent or stage do not work the way _global did, here’s what you do.

Use a Dispatch Event and write a custom event for your application. The cool thing about using events is they can act like _global events used too, but even better. You can call them from anywhere in you app, and you can listen and handle them almost anywhere you need to. This will open lots of doors in the way you can program your apps.

Lego Blocks


Think legos:

So let’s look at our object model. Like legos or blocks, some pieces have special functionality. like the window or door frame. These pieces are special and will function the same no matter what kind of crazy contraption we build with them.

I want to add some smart home functionality to my door and window. When I close the door, I want the window to close as well. Then when I wake-up and open my window, I want the door to open, to let all that beautiful air and scenery in, because this Lego home will be built in hawaii. Cool!

To show off the global variable class, I will add a locking variable that I can check from both the window and door. Not sure if you need locks in Hawaii, but you sure do where I come from.

package {
import flash.events.Event;

public class globalEvent extends Event{
public static var OPEN:String = "Open";
public static var CLOSE:String = "Close";
public static var UNLOCK:String = "Unlock";
public static var LOCK:String = "Lock";
public var targ:Object;
public function globalEvent(type:String, targ:Object, bubbles:Boolean = true, cancelable:Boolean = false){
super(type,bubbles,cancelable);
this.targ = targ;
}
}
}


Events:

So let’s put this into practice.

Custom events can have as many arguments as you want and are a very powerful way to communicate to other objects in your application.

One of the arguments in dispatch event is bubbles. Goofy name, but makes sense. This argument tells the dispatcher how far we want this shout-out (or bubble up) to be heard. We can keep it private, within our class or all the way to the root or stage (now we are talking _global baby!). Remember, Events can bubble up, not side to side. I can listen for an event at the container of the object dispatching the event, but not from another sibling or its children.

Event Bubbles Property


Better then _global:

In our Event we need to know when something is being opened and closed. So we will add OPEN and CLOSE as our public static vars. When the event is called, it will get dispatched to the super Event class, and we will be able to listen for OPEN and CLOSED events and build handlers to act accordingly. We can add listeners to the container (and above) for our window and door.

The way I used _global in AS2 for something like a navigation system, was to wait for a button press, loop through all the buttons, turning things on and off (rollovers and on-states) and other code. But, what would be even cooler, is if we could listen listen for our events from the siblings. All I have to do is target the listener to the parent of the object, like parent.addEventListener(). Wow!, no more looping through objects. Each object can listen for the event and act accordingly. My movie-clips just got smarter.

package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import global;

public class legoClip extends MovieClip{
public var Status:String = "Close";
public function legoClip(){
stop();
init();
}
function init(){
this.addEventListener(MouseEvent.MOUSE_UP,mouseup);
parent.addEventListener(globalEvent.OPEN, getClicked);
parent.addEventListener(globalEvent.CLOSE, getClicked);
}
function mouseup(ev:MouseEvent):void{

if(Status == "Close"){
if(!global._locked){
dispatchEvent(new globalEvent(globalEvent.OPEN,this));
gotoAndPlay("clipOpen");
Status = "Open";
}
}
else{
dispatchEvent(new globalEvent(globalEvent.CLOSE,this));
gotoAndPlay("clipClose");
Status = "Close";
}
}
function getClicked(e:globalEvent):void{
if(e.target != this){
//trace(e.target.name + " / " + e.type + " / " + this.name);
if(e.type == "Close"){
gotoAndPlay("clipClose");
Status = "Close";
}
else{
if(!global._locked){
gotoAndPlay("clipOpen");
Status = "Open";
}
}
}
}
}
}


Classes:

This app is so simple, writing class files are an overkill right? Wrong, the door and window look different, but the functionality and code to run them are exactly the same. So in this case, I only had to write the code for those two classes, once. One of the down-sides to using class files is it requires export to First Frame. And if you have a loader on the first frame, it will not show up until everything else loads. This kind of defeats the purpose of having a loader, but more about this later (I have some cool loader classes I will share). I like using class files as much as possible, for the sake of re-usability, (Code Once, Use Often, that’s my motto) plus it really is the best way you can animate and do code on a laptop without 2 monitors.


Dispatch Event:

Once everything is loaded and working using dispatch event, our event handlers need to tell out door and window to initiate their animations. The event class keeps track of the object that initiated the event, so we can easily test to see if this is the object that caused the event, if not, then it can respond.

Now we have super-smart clips that can be plugged in or out of our app, and everything will still work. Global does not look so cool any more. It kind of is easier, but not as cool. Now go and build some cool stuff!

[kml_flashembed movie=”http://www.taterboy.com/blog/flash/legos.swf” height=”208″ width=”414″ fversion=”9″ /]

source

What happened to _global, this site cost and _root, _level?

(Working With and Building Custom Events)

I rarely used _root or _level just because some projects would end up getting loaded into other swfs. Sometimes I didn’t know this until halfway through or in the end. So I started using global instead. That way I could still target the main timeline, which is where I would try to keep all my code, without having to worry about root moving somewhere else later. When I built components I would also use global, from time to time, to target them from anywhere in the application being developed.

The best workaround I have come across on the web for storing global variables, is to create a class object and throw all your variables in there. Some great information about this can be found here: http://www.uza.lt/codex/as3-global-object/

A brief simple example is something like this:

package {
public class global{
public static var Vars:Object = new Object();
public static var Arrs:Object = new Object();
public static var _locked:Boolean;

public function global(){

}
}
}


Notes: If you want to store dynamic variables (ones that are not predefined in the global Class) then you will need to send them to the Object Vars or Arrs (global.Vars.newVariable = “yo!”). Adding and updating arrays can be a little tricky, but I will write a lot more about this in the future. I am working on a watch/listener Class for AS3 that uses some of this functionality.

Like I mentioned earlier, it works great for variables, but not so much for global functions, which is what I used global for the most.


So Let the Griping Begin:

I know it is 3:00 am and you have deadlines. Now is not the time to re-think how to build your application. What in the world was Adobe thinking with AS3 anyway. Flash is a designers/animators tool to build pretty applications right? How in the world do they expect designers to learn this stuff. It took years to get the hang of AS2, now it feels like they have pulled the rug out from underneath us. Plus, now that programmers are the only ones able to program in Flash, expect a bunch of new Flash sites full of ugly stuff that moves.

Before I get too carried away, we should realize things aren’t so bad. Actually they are pretty good.

[ad#content_banner]


The Real Answer : Events

AS3 is much more of an Object Oriented Programming(OOP)d language then AS2. We can work around that fact, or we can embrace it. In an OOP mindset, we have to think of our project as made from objects (duh) that are children or siblings of other objects and communicate with each other using events. The new event and child systems are really powerful, it just takes a little getting used to.

When we have multiple objects that need to pass information to a central location, and parent or stage do not work the way _global did, here’s what you do.

Use a Dispatch Event and write a custom event for your application. The cool thing about using events is they can act like _global events used too, but even better. You can call them from anywhere in you app, and you can listen and handle them almost anywhere you need to. This will open lots of doors in the way you can program your apps.

Lego Blocks


Think legos:

So let’s look at our object model. Like legos or blocks, some pieces have special functionality. like the window or door frame. These pieces are special and will function the same no matter what kind of crazy contraption we build with them.

I want to add some smart home functionality to my door and window. When I close the door, I want the window to close as well. Then when I wake-up and open my window, I want the door to open, to let all that beautiful air and scenery in, because this Lego home will be built in hawaii. Cool!

To show off the global variable class, I will add a locking variable that I can check from both the window and door. Not sure if you need locks in Hawaii, but you sure do where I come from.

package {
import flash.events.Event;

public class globalEvent extends Event{
public static var OPEN:String = "Open";
public static var CLOSE:String = "Close";
public static var UNLOCK:String = "Unlock";
public static var LOCK:String = "Lock";
public var targ:Object;
public function globalEvent(type:String, targ:Object, bubbles:Boolean = true, cancelable:Boolean = false){
super(type,bubbles,cancelable);
this.targ = targ;
}
}
}


Events:

So let’s put this into practice.

Custom events can have as many arguments as you want and are a very powerful way to communicate to other objects in your application.

One of the arguments in dispatch event is bubbles. Goofy name, but makes sense. This argument tells the dispatcher how far we want this shout-out (or bubble up) to be heard. We can keep it private, within our class or all the way to the root or stage (now we are talking _global baby!). Remember, Events can bubble up, not side to side. I can listen for an event at the container of the object dispatching the event, but not from another sibling or its children.

Event Bubbles Property


Better then _global:

In our Event we need to know when something is being opened and closed. So we will add OPEN and CLOSE as our public static vars. When the event is called, it will get dispatched to the super Event class, and we will be able to listen for OPEN and CLOSED events and build handlers to act accordingly. We can add listeners to the container (and above) for our window and door.

The way I used _global in AS2 for something like a navigation system, was to wait for a button press, loop through all the buttons, turning things on and off (rollovers and on-states) and other code. But, what would be even cooler, is if we could listen listen for our events from the siblings. All I have to do is target the listener to the parent of the object, like parent.addEventListener(). Wow!, no more looping through objects. Each object can listen for the event and act accordingly. My movie-clips just got smarter.

package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import global;

public class legoClip extends MovieClip{
public var Status:String = "Close";
public function legoClip(){
stop();
init();
}
function init(){
this.addEventListener(MouseEvent.MOUSE_UP,mouseup);
parent.addEventListener(globalEvent.OPEN, getClicked);
parent.addEventListener(globalEvent.CLOSE, getClicked);
}
function mouseup(ev:MouseEvent):void{

if(Status == "Close"){
if(!global._locked){
dispatchEvent(new globalEvent(globalEvent.OPEN,this));
gotoAndPlay("clipOpen");
Status = "Open";
}
}
else{
dispatchEvent(new globalEvent(globalEvent.CLOSE,this));
gotoAndPlay("clipClose");
Status = "Close";
}
}
function getClicked(e:globalEvent):void{
if(e.target != this){
//trace(e.target.name + " / " + e.type + " / " + this.name);
if(e.type == "Close"){
gotoAndPlay("clipClose");
Status = "Close";
}
else{
if(!global._locked){
gotoAndPlay("clipOpen");
Status = "Open";
}
}
}
}
}
}


Classes:

This app is so simple, writing class files are an overkill right? Wrong, the door and window look different, but the functionality and code to run them are exactly the same. So in this case, I only had to write the code for those two classes, once. One of the down-sides to using class files is it requires export to First Frame. And if you have a loader on the first frame, it will not show up until everything else loads. This kind of defeats the purpose of having a loader, but more about this later (I have some cool loader classes I will share). I like using class files as much as possible, for the sake of re-usability, (Code Once, Use Often, that’s my motto) plus it really is the best way you can animate and do code on a laptop without 2 monitors.


Dispatch Event:

Once everything is loaded and working using dispatch event, our event handlers need to tell out door and window to initiate their animations. The event class keeps track of the object that initiated the event, so we can easily test to see if this is the object that caused the event, if not, then it can respond.

Now we have super-smart clips that can be plugged in or out of our app, and everything will still work. Global does not look so cool any more. It kind of is easier, but not as cool. Now go and build some cool stuff!

[kml_flashembed movie=”http://www.taterboy.com/blog/flash/legos.swf” height=”208″ width=”414″ fversion=”9″ /]

source
I really enjoy coding in AS3, advice but one of the things I dislike the most is the fact that when building movieclips as Classes, information pills you have to export to Action Script or place all your movieclips on the stage somewhere. I think the latter is not very flexible. I understand why it has to be done; I just don’t like it. The problem with exporting everything to the Action Script is that it loads that MovieClip on the first frame, try and loaders that are normally placed on the first frame will not show up or function until the first frame is loaded. This first frame now contains all our content that we have exported to Action Script which really defeats the purpose of a loader. That is why you will see a blank white box for a few seconds or longer before the loader shows up. The best way to fix this is to build a loader swf  to load our current project swf into. 

But you know what would be even cooler?  A Super Loader!
This super loader could be so smart, that we could code it once, then use it as a loader for every project we do in the future. It will load in any-size swf at any frame-rate, and to get even sicker, let’s make the loader bar or display animation external so that we can make many different loaders  for different projects and have them work with this super loader as well. 

So welcome to Super Loader and Super Stage.
A few of the features we will be using to pull this off are the new Stage frameRate, Loader and ProgressEvent classes.

Step 1: Host SWF and SuperStage Class.
The host file is a blank fla that points to our SuperStage Class. We do not care about what size it is, what color the background is or the frame rate. We will be able to control all that later with our SuperStage Class.

The Code:
Open the package and import all the needed Classes. I am organizing these classes more like I would if I were working on a large project. Hence the com.HDI.stage. You could remove this and place the .as file in the same directory as the .fla if that is easier.

package com.HDI.stage {
/*import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;*/
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;
import com.HDI.events.loaderEvent;

public class SuperStage extends MovieClip {
//External Variables:
//var thisWidth:Number = 800;
//var thisHeight:Number = 600;
var fps:Number = 30;
var swfURL:String = "imgViewer.swf";
var ldrURL:String = "loaderbar.swf";

//Loader Variables:
var loadComplete:Boolean = false;
var loadPerc:Number;
var loaderCnt:Number = 0;

//Internal Objects:
var mainMovie:Object;
var mainLdr:Object;
var mainContainer:MovieClip;
var loaderMC:MovieClip;

public function SuperStage():void{
init();
}
private function init():void{
//Set all the stage properties onload
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//load the main container and the loader container
/*
this is not manditory and can make things more complex,
but so that the loader always stays on top, I add these to MovieClips
then load everything else inside these clips.
Load the loaderMC second so that it remains on top.
*/
mainContainer = new MovieClip();
addChild(mainContainer);
loaderMC = new MovieClip();
addChild(loaderMC);

//setup stage init incase I need it later.
loaderInfo.addEventListener(Event.INIT,initStage);

//start to load the loader bar.
loadObject(loaderMC,ldrURL,null,ldrFin);
stop();
addEventListener(loaderEvent.LOAD,loadNewObject);

}
function initStage(ev:Event):void{
//stage.stageWidth = thisWidth;
//stage.stageHeight = thisHeight;
}
}
}

[ad#content_banner]

It is supposed to be a best practice to not have a lot of code in your class method. I use an init function to set everything up. This is a very similar practice to flex programming when you call an init function on creationComplete. Another advantage is that we can call init(), if it is public, from an external source or to reload/reset the class.

In this init function we will set up all of our stage properties. When everything loads we want to have a loader bar that appears in the center of the screen while the main content is loading. Being a super loader, it will need to appear on top of everything, and we can use it later to load in other content. When Flash loads new content, it will load new stuff on top of the old stuff. So to make sure our loader stays on top without swapping depths all the time, we will add a main content MovieClip to the stage first, then add our loader MovieClip. Now load all the content into the main content clip which will always exist below the loader MovieClip.

Step 2: Main Loader Engine

Using the Object Loader method we can load in our loader bar, main content, and any other swfs or images in the future. 

function loadNewObject(ev:loaderEvent):void{
loadObject(ev.ldrTarget,ev.ldrURL,mainLdr,ev.ldrFunction);
}
//main loader method
function loadObject(targ:Object,path:String,mon:Object,funFunction:Function):void{
var ldr:Loader = new Loader();
var ldrReq:URLRequest = new URLRequest(path);
ldr.load(ldrReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, funFunction);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ldrProgress);
ldr.name = "ldr" + loaderCnt;
targ.addChild(ldr);
loaderCnt ++;
}
//finish loading. first two items loaded will be ldr0(loader bar) and ldr1(main content)
function ldrFin(ev:Event):void{
if(ev.target.loader.name == "ldr0"){
mainLdr = ev.target.content;
mainLdr.loadStat = true;
mainLdr.x = (stage.stageWidth/2)-(mainLdr.width/2);
mainLdr.y = (stage.stageHeight/2)-(mainLdr.height/2);
loadObject(mainContainer,swfURL,mainLdr,ldrFin);
}
else if(ev.target.loader.name == "ldr1"){
mainMovie = ev.target.content;
stage.frameRate = ev.target.frameRate;
}
}
//progress handler, sends loading info to loader bar.
function ldrProgress(ev:ProgressEvent):void{
if(mainLdr){
mainLdr.ldrMon(ev.bytesLoaded/ev.bytesTotal);
}
}

Note:
The targeting of objects after they are loaded can be a little tricky. There is the main movie clip as the parent, the loader object, then the loader content. If you are managing a large amount of MovieClips then it may be a good idea to add each object to an array as they are loaded.

The frameRate is set when the main content loads. The width and height  and background colors are established by the html host file which makes this loader pretty flexible. Right now you have to change the urls to the loader and swf, which isn’t so super, but they can be moved out into the html embed code as variables or we can change the names of our files to be more generic. My next post will go into more depth about implementing this into a workflow and how to automatically configuring the super loader on publish. So come back soon.

In the meantime, we can work on our loader bar.
You can see in the following code that there is a loader bar and monitoring code for the content being loaded. We also set the loaders x and y position to be dead center of our stage dynamically depending on the size of the main content.

package com.HDI.loaders {

import flash.display.Sprite;
import flash.display.MovieClip;

public class LdrBar extends MovieClip{
//load status. I may need this later
public var loadStat:Boolean;
public function LdrBar():void{
stop();
init();
}
public function init():void{
//On init, loader animation and bar size is reset.
//The best part of use the init function instead of the
//class method, is that I can call this anytime to reset the loader.
ani.stop();
bar.scaleX = 0.01;
}
public function ldrMon(perc:Number):void{
//main loader animation control.
//this method is called from the host using the progress event.
//as the progress changes, the loader becomes visible and the animation plays.
if(perc < 1){
visible = true;
bar.scaleX = perc;
ani.play();
}
else{
// when progress stops, loader becomes invisible and animation stops.
ani.stop();
visible =false;

}
}
}
}

Step 3: Loader Bar Animation and Image Viewer.
The Super part of this loader is the fact that you can create new loader  graphics, animation, and progress indicators; and load those in without changing any code in our super stage. The host file only cares about loading in something; it can even be an image. Then the loader will receive and update every time the progress changes. It would be a pretty boring loader if it were an image, but the point has been made that it could be.

This loader acts like a loader bar with an animation effect that is visible when progress is updated and invisible when there is no progress. I have included a simple image viewer to show how to use the same loader for everything that is loaded into our main movie. If you have a fast connection, then you may not see much and will have to take my word for it, It looks awesome! And how do we call the loader feature from our main movie? Using a dispatchEvent  and a custom event of course, you can read more about that here if you haven’t already.

I hope you enjoyed this tutorial and stay tuned for the next post which will take these super components and integrate them into a workflow that can only be described as, well, “Super”.

[kml_flashembed movie=”/blog/flash/superLoader/mainFlash.swf” height=”280″ width=”472″ fversion=”9″ /]

source

UPDATE:

Someone asked how to remove loaded items. The image viewer example above just stacks one image on top of another.  If you have swfs with music and/or animation this can cause problems. If you are using the same MovieClip as a holder for all of your loaded items, then place a new MovieClip as a child of the holder and load all items in the child, that way you can remove the childClip before loading new objects.

This is a modification that can beadded to the imgViewer.fla in the source files.

function mouseHandler(ev:MouseEvent):void{
imgLoader.visible = false;
instructions.visible = false;
//-- new code
if(imgLoader.numChildren > 0){
imgLoader.removeChild(imgLoader.getChildByName("imgHolder1"));
}
var tempIMG:MovieClip = new MovieClip();
tempIMG.name = "imgHolder1";
imgLoader.addChild(tempIMG);
// -- end new code

dispatchEvent(new loaderEvent(loaderEvent.LOAD,tempIMG,"images/3d_sketch.jpg",imgLoaded));
// replace all instances of "imgLoader" with "tempIMG" in the event dispatchers.

}

***Cleaner way is to use the childMonitor Class and the pullAll() method to remove all items before loading a new item.

import com.hdi.util.ChildMonitor;
var cmt:ChildMonitor = new ChildMonitor(imgLoader);

function mouseHandler(ev:MouseEvent):void{
imgLoader.visible = false;
instructions.visible = false;
//-- new code
if(cmt.childList.length > 1){
cmt.pullAll();
}
// -- end new code

dispatchEvent(new loaderEvent(loaderEvent.LOAD,imgLoader,"images/3d_sketch.jpg",imgLoaded));

}

What happened to _global, this site cost and _root, _level?

(Working With and Building Custom Events)

I rarely used _root or _level just because some projects would end up getting loaded into other swfs. Sometimes I didn’t know this until halfway through or in the end. So I started using global instead. That way I could still target the main timeline, which is where I would try to keep all my code, without having to worry about root moving somewhere else later. When I built components I would also use global, from time to time, to target them from anywhere in the application being developed.

The best workaround I have come across on the web for storing global variables, is to create a class object and throw all your variables in there. Some great information about this can be found here: http://www.uza.lt/codex/as3-global-object/

A brief simple example is something like this:

package {
public class global{
public static var Vars:Object = new Object();
public static var Arrs:Object = new Object();
public static var _locked:Boolean;

public function global(){

}
}
}


Notes: If you want to store dynamic variables (ones that are not predefined in the global Class) then you will need to send them to the Object Vars or Arrs (global.Vars.newVariable = “yo!”). Adding and updating arrays can be a little tricky, but I will write a lot more about this in the future. I am working on a watch/listener Class for AS3 that uses some of this functionality.

Like I mentioned earlier, it works great for variables, but not so much for global functions, which is what I used global for the most.


So Let the Griping Begin:

I know it is 3:00 am and you have deadlines. Now is not the time to re-think how to build your application. What in the world was Adobe thinking with AS3 anyway. Flash is a designers/animators tool to build pretty applications right? How in the world do they expect designers to learn this stuff. It took years to get the hang of AS2, now it feels like they have pulled the rug out from underneath us. Plus, now that programmers are the only ones able to program in Flash, expect a bunch of new Flash sites full of ugly stuff that moves.

Before I get too carried away, we should realize things aren’t so bad. Actually they are pretty good.

[ad#content_banner]


The Real Answer : Events

AS3 is much more of an Object Oriented Programming(OOP)d language then AS2. We can work around that fact, or we can embrace it. In an OOP mindset, we have to think of our project as made from objects (duh) that are children or siblings of other objects and communicate with each other using events. The new event and child systems are really powerful, it just takes a little getting used to.

When we have multiple objects that need to pass information to a central location, and parent or stage do not work the way _global did, here’s what you do.

Use a Dispatch Event and write a custom event for your application. The cool thing about using events is they can act like _global events used too, but even better. You can call them from anywhere in you app, and you can listen and handle them almost anywhere you need to. This will open lots of doors in the way you can program your apps.

Lego Blocks


Think legos:

So let’s look at our object model. Like legos or blocks, some pieces have special functionality. like the window or door frame. These pieces are special and will function the same no matter what kind of crazy contraption we build with them.

I want to add some smart home functionality to my door and window. When I close the door, I want the window to close as well. Then when I wake-up and open my window, I want the door to open, to let all that beautiful air and scenery in, because this Lego home will be built in hawaii. Cool!

To show off the global variable class, I will add a locking variable that I can check from both the window and door. Not sure if you need locks in Hawaii, but you sure do where I come from.

package {
import flash.events.Event;

public class globalEvent extends Event{
public static var OPEN:String = "Open";
public static var CLOSE:String = "Close";
public static var UNLOCK:String = "Unlock";
public static var LOCK:String = "Lock";
public var targ:Object;
public function globalEvent(type:String, targ:Object, bubbles:Boolean = true, cancelable:Boolean = false){
super(type,bubbles,cancelable);
this.targ = targ;
}
}
}


Events:

So let’s put this into practice.

Custom events can have as many arguments as you want and are a very powerful way to communicate to other objects in your application.

One of the arguments in dispatch event is bubbles. Goofy name, but makes sense. This argument tells the dispatcher how far we want this shout-out (or bubble up) to be heard. We can keep it private, within our class or all the way to the root or stage (now we are talking _global baby!). Remember, Events can bubble up, not side to side. I can listen for an event at the container of the object dispatching the event, but not from another sibling or its children.

Event Bubbles Property


Better then _global:

In our Event we need to know when something is being opened and closed. So we will add OPEN and CLOSE as our public static vars. When the event is called, it will get dispatched to the super Event class, and we will be able to listen for OPEN and CLOSED events and build handlers to act accordingly. We can add listeners to the container (and above) for our window and door.

The way I used _global in AS2 for something like a navigation system, was to wait for a button press, loop through all the buttons, turning things on and off (rollovers and on-states) and other code. But, what would be even cooler, is if we could listen listen for our events from the siblings. All I have to do is target the listener to the parent of the object, like parent.addEventListener(). Wow!, no more looping through objects. Each object can listen for the event and act accordingly. My movie-clips just got smarter.

package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import global;

public class legoClip extends MovieClip{
public var Status:String = "Close";
public function legoClip(){
stop();
init();
}
function init(){
this.addEventListener(MouseEvent.MOUSE_UP,mouseup);
parent.addEventListener(globalEvent.OPEN, getClicked);
parent.addEventListener(globalEvent.CLOSE, getClicked);
}
function mouseup(ev:MouseEvent):void{

if(Status == "Close"){
if(!global._locked){
dispatchEvent(new globalEvent(globalEvent.OPEN,this));
gotoAndPlay("clipOpen");
Status = "Open";
}
}
else{
dispatchEvent(new globalEvent(globalEvent.CLOSE,this));
gotoAndPlay("clipClose");
Status = "Close";
}
}
function getClicked(e:globalEvent):void{
if(e.target != this){
//trace(e.target.name + " / " + e.type + " / " + this.name);
if(e.type == "Close"){
gotoAndPlay("clipClose");
Status = "Close";
}
else{
if(!global._locked){
gotoAndPlay("clipOpen");
Status = "Open";
}
}
}
}
}
}


Classes:

This app is so simple, writing class files are an overkill right? Wrong, the door and window look different, but the functionality and code to run them are exactly the same. So in this case, I only had to write the code for those two classes, once. One of the down-sides to using class files is it requires export to First Frame. And if you have a loader on the first frame, it will not show up until everything else loads. This kind of defeats the purpose of having a loader, but more about this later (I have some cool loader classes I will share). I like using class files as much as possible, for the sake of re-usability, (Code Once, Use Often, that’s my motto) plus it really is the best way you can animate and do code on a laptop without 2 monitors.


Dispatch Event:

Once everything is loaded and working using dispatch event, our event handlers need to tell out door and window to initiate their animations. The event class keeps track of the object that initiated the event, so we can easily test to see if this is the object that caused the event, if not, then it can respond.

Now we have super-smart clips that can be plugged in or out of our app, and everything will still work. Global does not look so cool any more. It kind of is easier, but not as cool. Now go and build some cool stuff!

[kml_flashembed movie=”http://www.taterboy.com/blog/flash/legos.swf” height=”208″ width=”414″ fversion=”9″ /]

source
I really enjoy coding in AS3, advice but one of the things I dislike the most is the fact that when building movieclips as Classes, information pills you have to export to Action Script or place all your movieclips on the stage somewhere. I think the latter is not very flexible. I understand why it has to be done; I just don’t like it. The problem with exporting everything to the Action Script is that it loads that MovieClip on the first frame, try and loaders that are normally placed on the first frame will not show up or function until the first frame is loaded. This first frame now contains all our content that we have exported to Action Script which really defeats the purpose of a loader. That is why you will see a blank white box for a few seconds or longer before the loader shows up. The best way to fix this is to build a loader swf  to load our current project swf into. 

But you know what would be even cooler?  A Super Loader!
This super loader could be so smart, that we could code it once, then use it as a loader for every project we do in the future. It will load in any-size swf at any frame-rate, and to get even sicker, let’s make the loader bar or display animation external so that we can make many different loaders  for different projects and have them work with this super loader as well. 

So welcome to Super Loader and Super Stage.
A few of the features we will be using to pull this off are the new Stage frameRate, Loader and ProgressEvent classes.

Step 1: Host SWF and SuperStage Class.
The host file is a blank fla that points to our SuperStage Class. We do not care about what size it is, what color the background is or the frame rate. We will be able to control all that later with our SuperStage Class.

The Code:
Open the package and import all the needed Classes. I am organizing these classes more like I would if I were working on a large project. Hence the com.HDI.stage. You could remove this and place the .as file in the same directory as the .fla if that is easier.

package com.HDI.stage {
/*import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;*/
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;
import com.HDI.events.loaderEvent;

public class SuperStage extends MovieClip {
//External Variables:
//var thisWidth:Number = 800;
//var thisHeight:Number = 600;
var fps:Number = 30;
var swfURL:String = "imgViewer.swf";
var ldrURL:String = "loaderbar.swf";

//Loader Variables:
var loadComplete:Boolean = false;
var loadPerc:Number;
var loaderCnt:Number = 0;

//Internal Objects:
var mainMovie:Object;
var mainLdr:Object;
var mainContainer:MovieClip;
var loaderMC:MovieClip;

public function SuperStage():void{
init();
}
private function init():void{
//Set all the stage properties onload
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//load the main container and the loader container
/*
this is not manditory and can make things more complex,
but so that the loader always stays on top, I add these to MovieClips
then load everything else inside these clips.
Load the loaderMC second so that it remains on top.
*/
mainContainer = new MovieClip();
addChild(mainContainer);
loaderMC = new MovieClip();
addChild(loaderMC);

//setup stage init incase I need it later.
loaderInfo.addEventListener(Event.INIT,initStage);

//start to load the loader bar.
loadObject(loaderMC,ldrURL,null,ldrFin);
stop();
addEventListener(loaderEvent.LOAD,loadNewObject);

}
function initStage(ev:Event):void{
//stage.stageWidth = thisWidth;
//stage.stageHeight = thisHeight;
}
}
}

[ad#content_banner]

It is supposed to be a best practice to not have a lot of code in your class method. I use an init function to set everything up. This is a very similar practice to flex programming when you call an init function on creationComplete. Another advantage is that we can call init(), if it is public, from an external source or to reload/reset the class.

In this init function we will set up all of our stage properties. When everything loads we want to have a loader bar that appears in the center of the screen while the main content is loading. Being a super loader, it will need to appear on top of everything, and we can use it later to load in other content. When Flash loads new content, it will load new stuff on top of the old stuff. So to make sure our loader stays on top without swapping depths all the time, we will add a main content MovieClip to the stage first, then add our loader MovieClip. Now load all the content into the main content clip which will always exist below the loader MovieClip.

Step 2: Main Loader Engine

Using the Object Loader method we can load in our loader bar, main content, and any other swfs or images in the future. 

function loadNewObject(ev:loaderEvent):void{
loadObject(ev.ldrTarget,ev.ldrURL,mainLdr,ev.ldrFunction);
}
//main loader method
function loadObject(targ:Object,path:String,mon:Object,funFunction:Function):void{
var ldr:Loader = new Loader();
var ldrReq:URLRequest = new URLRequest(path);
ldr.load(ldrReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, funFunction);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ldrProgress);
ldr.name = "ldr" + loaderCnt;
targ.addChild(ldr);
loaderCnt ++;
}
//finish loading. first two items loaded will be ldr0(loader bar) and ldr1(main content)
function ldrFin(ev:Event):void{
if(ev.target.loader.name == "ldr0"){
mainLdr = ev.target.content;
mainLdr.loadStat = true;
mainLdr.x = (stage.stageWidth/2)-(mainLdr.width/2);
mainLdr.y = (stage.stageHeight/2)-(mainLdr.height/2);
loadObject(mainContainer,swfURL,mainLdr,ldrFin);
}
else if(ev.target.loader.name == "ldr1"){
mainMovie = ev.target.content;
stage.frameRate = ev.target.frameRate;
}
}
//progress handler, sends loading info to loader bar.
function ldrProgress(ev:ProgressEvent):void{
if(mainLdr){
mainLdr.ldrMon(ev.bytesLoaded/ev.bytesTotal);
}
}

Note:
The targeting of objects after they are loaded can be a little tricky. There is the main movie clip as the parent, the loader object, then the loader content. If you are managing a large amount of MovieClips then it may be a good idea to add each object to an array as they are loaded.

The frameRate is set when the main content loads. The width and height  and background colors are established by the html host file which makes this loader pretty flexible. Right now you have to change the urls to the loader and swf, which isn’t so super, but they can be moved out into the html embed code as variables or we can change the names of our files to be more generic. My next post will go into more depth about implementing this into a workflow and how to automatically configuring the super loader on publish. So come back soon.

In the meantime, we can work on our loader bar.
You can see in the following code that there is a loader bar and monitoring code for the content being loaded. We also set the loaders x and y position to be dead center of our stage dynamically depending on the size of the main content.

package com.HDI.loaders {

import flash.display.Sprite;
import flash.display.MovieClip;

public class LdrBar extends MovieClip{
//load status. I may need this later
public var loadStat:Boolean;
public function LdrBar():void{
stop();
init();
}
public function init():void{
//On init, loader animation and bar size is reset.
//The best part of use the init function instead of the
//class method, is that I can call this anytime to reset the loader.
ani.stop();
bar.scaleX = 0.01;
}
public function ldrMon(perc:Number):void{
//main loader animation control.
//this method is called from the host using the progress event.
//as the progress changes, the loader becomes visible and the animation plays.
if(perc < 1){
visible = true;
bar.scaleX = perc;
ani.play();
}
else{
// when progress stops, loader becomes invisible and animation stops.
ani.stop();
visible =false;

}
}
}
}

Step 3: Loader Bar Animation and Image Viewer.
The Super part of this loader is the fact that you can create new loader  graphics, animation, and progress indicators; and load those in without changing any code in our super stage. The host file only cares about loading in something; it can even be an image. Then the loader will receive and update every time the progress changes. It would be a pretty boring loader if it were an image, but the point has been made that it could be.

This loader acts like a loader bar with an animation effect that is visible when progress is updated and invisible when there is no progress. I have included a simple image viewer to show how to use the same loader for everything that is loaded into our main movie. If you have a fast connection, then you may not see much and will have to take my word for it, It looks awesome! And how do we call the loader feature from our main movie? Using a dispatchEvent  and a custom event of course, you can read more about that here if you haven’t already.

I hope you enjoyed this tutorial and stay tuned for the next post which will take these super components and integrate them into a workflow that can only be described as, well, “Super”.

[kml_flashembed movie=”/blog/flash/superLoader/mainFlash.swf” height=”280″ width=”472″ fversion=”9″ /]

source

UPDATE:

Someone asked how to remove loaded items. The image viewer example above just stacks one image on top of another.  If you have swfs with music and/or animation this can cause problems. If you are using the same MovieClip as a holder for all of your loaded items, then place a new MovieClip as a child of the holder and load all items in the child, that way you can remove the childClip before loading new objects.

This is a modification that can beadded to the imgViewer.fla in the source files.

function mouseHandler(ev:MouseEvent):void{
imgLoader.visible = false;
instructions.visible = false;
//-- new code
if(imgLoader.numChildren > 0){
imgLoader.removeChild(imgLoader.getChildByName("imgHolder1"));
}
var tempIMG:MovieClip = new MovieClip();
tempIMG.name = "imgHolder1";
imgLoader.addChild(tempIMG);
// -- end new code

dispatchEvent(new loaderEvent(loaderEvent.LOAD,tempIMG,"images/3d_sketch.jpg",imgLoaded));
// replace all instances of "imgLoader" with "tempIMG" in the event dispatchers.

}

***Cleaner way is to use the childMonitor Class and the pullAll() method to remove all items before loading a new item.

import com.hdi.util.ChildMonitor;
var cmt:ChildMonitor = new ChildMonitor(imgLoader);

function mouseHandler(ev:MouseEvent):void{
imgLoader.visible = false;
instructions.visible = false;
//-- new code
if(cmt.childList.length > 1){
cmt.pullAll();
}
// -- end new code

dispatchEvent(new loaderEvent(loaderEvent.LOAD,imgLoader,"images/3d_sketch.jpg",imgLoaded));

}

All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books

‘;
echo ‘

‘;
echo getItem(‘0465050654’, approved ‘taterboy-20’);
echo ‘

‘;
echo getItem(‘0321980042’, site ‘taterboy-20’);
echo ‘

‘;
echo getItem(‘0941188108′,’taterboy-20’);
echo ‘

‘;
echo getItem(‘1560100842′,’taterboy-20’);
echo ‘

‘;

echo ‘

Games

‘;
echo ‘

‘;
echo getItem(‘B01GP2070E’,’taterboy-20′);
echo ‘

‘;
echo getItem(‘B00U1U34IE’,’taterboy-20′);
echo ‘

‘;
echo getItem(‘B01GW3LR8M’,’taterboy-20′);
echo ‘

‘;
echo getItem(‘B01GW3PAYE’,’taterboy-20′);
echo ‘

‘;
?>

All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books’;
echo ‘

‘;
echo getItem(‘0465050654’, symptoms link ‘taterboy-20’);
echo ‘
‘;
echo getItem(‘0321980042′,’taterboy-20’);
echo ‘
‘;
echo getItem(‘0941188108′,’taterboy-20’);
echo ‘
‘;
echo getItem(‘1560100842′,’taterboy-20’) . ‘

If you animate, learn the fundamentals.

‘;
echo ‘

‘;

echo ‘

Games

‘;
echo ‘

‘;
echo getItem(‘B01GP2070E’,’taterboy-20′);
echo ‘
‘;
echo getItem(‘B00U1U34IE’,’taterboy-20′);
echo ‘
‘;
echo getItem(‘B01GW3LR8M’,’taterboy-20′);
echo ‘
‘;
echo getItem(‘B01GW3PAYE’,’taterboy-20′);
echo ‘

‘;

All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books’;
echo ‘

‘;
echo getItem(‘0465050654’, symptoms link ‘taterboy-20’);
echo ‘
‘;
echo getItem(‘0321980042′,’taterboy-20’);
echo ‘
‘;
echo getItem(‘0941188108′,’taterboy-20’);
echo ‘
‘;
echo getItem(‘1560100842′,’taterboy-20’) . ‘

If you animate, learn the fundamentals.

‘;
echo ‘

‘;

echo ‘

Games

‘;
echo ‘

‘;
echo getItem(‘B01GP2070E’,’taterboy-20′);
echo ‘
‘;
echo getItem(‘B00U1U34IE’,’taterboy-20′);
echo ‘
‘;
echo getItem(‘B01GW3LR8M’,’taterboy-20′);
echo ‘
‘;
echo getItem(‘B01GW3PAYE’,’taterboy-20′);
echo ‘

‘;

UPDATE 1.20, troche 4/21/11 : new source files below

Animation is the primary reason our clients choose Flash based applications over HTML or any other language. Creating applications that dance is the “Rich” in RIA development.

Great animation or tween engines are plenty, GTween, TweenLite and Tweener are just a few. They provide a simpler way of animating with code. The Flash IDE team has also gone to great lengths to make working with animation in code easier for the designers. Even Flash Builder 4, which one could argue is a programmers tool, has new animation classes that are far more powerful than their predecessors.


Interactive Demos below…

Animation is what makes Flash, Flash:
MoveThis has been around in many different forms as my personal tween engine for the last 8 years. I think it’s finally in a condition that it can be shared. The idea has always been one line of code to make something move, it’s extremely simple to use, yet supports many great features.

This latest incarnation has focused on performance. Something that would work great for building mobile applications. It isn’t perfect, or the only solution, but it works with my approach to building applications and games that require a great deal of animation.

Most tween engines work on the theory that a tween is something to keep around and run backwards and forwards, something like a video file with a play and pause function. MoveThis is based on an idea that there are so many tweens in an application, trying to manage pausing, reversing, playing and completion events gets too complicated or resource heavy.

Using MoveThis has 4 requirements:
1. know the display object to move.
2. know which property of the display object to animate.
3. know that target value of the display object property.
4. know how many frames the tween will span.

The resulting code looks like this:

MoveThis.startTween(foo,{x:500},30);

…which animates the x property of “foo” to a value of 500 over 30 frames. There are no start methods to call or instances to manage. Once the tween is complete it is nulled out and garbage collected.

Performance:
MoveThis is fairly light and very good on performance. MoveThis can run about 5000 tweens simultaneously at 24 frames per second and create *6500 new tweens in 1 second at 20 frames per second. MoveThis will add about 9k to your application.

*Note: One of the benefits of MoveThis is that it eliminates duplicate tweens, this constant cleaning can cause performance lags when adding a large amount ( > 250 ) of tweens on one frame. To get the type of performance claimed above, set ignoreDupes to true.

MoveThis.ignoreDupes = true;

Pros:
MoveThis uses 1 EventListener for all tweens, also onComplete, onStart and onFrame events use callbacks instead of Events which is better for mobile application performance. Optimized to work with thousands of tweens without worrying about duplicates or stopping tweens.

Cons:
Maybe not the best solution for a project with just a few animations that need to loop, stop, pause, play and rewind.

Now lets talk features!

Standard Features:
1. MoveThis is frame based, I have found that even the Timer class is not consistent from client to client based on processor speed, so we might as well use frames which is more accustom to animation. At some point I may add getTime and audio syncing.

2. onComplete, onStart, onFrame as callbacks instead of events, which preserves performance. Returns a references to the object being animated.

3. The pause tween: for when you want to call a function later, after a few frames, again without adding new events or timers.

4. visible = true: if something is animating, then it is probably meant to be seen, MoveThis automatically turns the visible property to true when the tween begins. (can be overridden)

5. One tween per object property at a time: This is one of the main reason MoveThis was created the way it was. Users changes there minds without waiting for tweens to complete. MoveThis will replace older, in progress tweens with a new one, picking up where the last tween left off.

6. Plugins: animate non-numeric properties, such as matrix, color, brightness, volume with custom plugins. (color and brightness plugins included)

7. queue tweens: when limiting one tween per property at a time, tweens can be queued for later, without overwriting a current tween. Just like startTween, except the first argument sets how many frames the tween will remain in the queue.

MoveThis.queueTween(30, foo,{x:500},30);

8. pause: pause a current tween or all tweens

9. stop an individual tween or stop all current tweens for each display object.

10. When a tween is completed it is nulled out, freeing up memory for other stuff.

11: based on standard easing functions: includes Reverse and Arch easing functions, as well as, standard easing functions by Robert Penner.

How it Works:
Arguments:
1. targObject: (Object) A reference to the object that is to be animated.
2. propValues: (Object) An object containing all the numeric properties or plugins of the object that are to be tweened.
3. frames: (int) The amount of frames the tweens will span.
4. extras: (Object) Many features such as onComplete, easingFunction, loop and delay are set in the extras object.

MoveThis.startTween(foo,{x:500},30,{onComplete:completeHandler,easing:"Sine.EaseIn",delay:30});


[kml_flashembed fversion=”10.0.0″ movie=”http://www.taterboy.com/blog/flash/MoveThisDemo.swf” targetclass=”flashmovie” publishmethod=”static” width=”500″ height=”400″]

Get Adobe Flash player

[/kml_flashembed]

Extras (and how they work):
1. delay: (int) the frame count before the tween starts.

2. ease: (Number, 0 – 1) Adds an ease percentage to any easing function. designers like to add verity and subtlety to their animations, easing functions are no longer all or nothing.

3. easingFunction: (Function) Use standard or custom easing functions.

4. easing: (String, “Bounce.easeIn” ) Standard easing functions can be declared as a string, which elevates the need to import easing classes which helps in testing out a few different easing functions, trying to find that perfect ease.

5. loop: (Boolean) An animations can loop infinitely or just a few times.

6. visibility: (Boolean, false) Sets an object’s visible property to false after a tween.

7. startVisible: (Boolean, false) Override the default behavior of automatically setting an object’s visible property to true on the first frame of the tween.

8. remove: (Boolean) Automatically remove a display object or element after the tween is completed.

9. uid: (int ) A unique identifier, used for pause tweens, so they can be overwritten.

10. onStart, onFrame, onComplete: (Function) Callback functions, returns a reference to the animated object.

11. smartRotation: (Boolean) Forces the tween to rotate in the direction of the closest angle.

12. removeDupes: (Boolean, true) Default behavior is to remove all duplicates, but to save performance, you may want to turn this feature off and manage it on a per tween basis.

One Tween at a time:
Not to be stuck in an endless loop here, but this has a huge impact of how MoveThis is used, so one last time; I promise. Once a tween is completed in the MoveThis engine, it is removed and nulled out. If you need to reverse a tween or replay a previous tween, the best procedure is to start a new tween. MoveThis only allows one tween per property per object to occur at a time. If a tween is started on the x property of a displayObject named foo over 30 frames, when another tween is started just a few frames later for the same object’s x property, the first tween will be replaced by the new tween. Once the new tween is finished, it will be removed forever, unless a loop count was added.

One Tween for each property:
When a tween is started, an object (MoveThisObject) is created for each property to be animated. Each tween object is then animated separately. This allows you to start one tween with multiple properties, then update the animation by starting a new tween with of single property value.

Example:

//initial tween
MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30);

//something in our app changes, that require foo to fade out.
MoveThis.startTween(foo,{alpha:0},30);

The x and y properties will continue to tween while the alpha property tween for foo will be replaced and the new fade out tween will began.

The repercussions are that if you have onComplete, onStart, onFrame callbacks assigned to that tween, the callbacks will be called for each property. In the following example, the function “completeHandler” will be called twice, once on complete of the x tween and once on the complete of the y tween.

Example:

MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30,{onComplete:completeHandler);

Three Ways to Make Things Happen Later:
1. delay: The simplest way to delay a tween.

//wait 20 frames before starting
MoveThis.startTween(foo,{x:500},30,{delay:20});

Note: If this is used and another tween is added for the x property of foo, it will be replaced, even if the delay has not expired

2. queueTween: When you know you want to move something later, but do not want it to overwrite a current tween.

//queue this tween for 30 frames
MoveThis.queueTween(30,foo,{x:500});

Note: Once the queue time is complete, the queued tween will replace any existing tweens for the same property of the same object.

3. The pause tween: Used when you want to call a function after a certain number of frames. Easier and requires less processor than using the Timer class.

//call pauseHandler after 90 frames.
MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler});

Note: Frame count is ignored. The pause tween must include an onComplete function.

Note: Replace null with a displayObject reference to have that reference sent to the onComplete function.

Unique ID: By default all pause tweens are persistent, meaning duplicates for the pause property are allowed to exist. If you need to overwrite a pause tween, then give the tween a unique id, when a new pause tween is created with the same id, it will overwrite the previous one.

MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler,uid:1});

[ad#content_banner]

onComplete Function Example:

function completeHandler(obj:Object):void{
//all target references are returned as objects.
//this allows you to start a new animation or modify the target when the animation is completed
if(obj != null)
obj.visible = false;
}

Easing:
Easing works very similar to all the existing tween/animation engines and works with any standardized easing functions. There are three ways to add eases to your animation.

1. easingFunction: This is the most typical ways of adding ease to a tween. Add a reference to any standardized easing function and you are done.

//add Sine.easeOut as the easingFunction. (the Sine.EaseOut class must be imported first)
MoveThis.startTween(foo,{x:500},30,{easingFunction:Sine.easeOut});

2. easing: An alternate method of #1 and for lazy people like me or someone that wants to try out a few different easing functions without importing them all. Enter one of the included standard tween function names as a string and MoveThis imports the correct easing function for you.

//add Sine.easeOut as the easingFunction without importing the class
MoveThis.startTween(foo,{x:500},30,{easing:"Sine.easeOut"});

3. easingStrength: Not every easing function has to be 100% all or nothing. Adding a 0 – 1 value will allow you to have a little less ease if needed.

//add Quart.easeOut as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{easing:"Quart.easeOut",easingStrength:0.6});

4. ease: Works just like the Flash IDE, set ease from -1 to 1 to automatically add Sine.easeOut or Sine.easeIn, depending on the value.

//add Sine.easeIn as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{ease:-0.6});

Note: There are two easing classes included to enable looping animations that reverse before looping again. (Arch.linear, Arch.easeIn, Arch.easeOut, Reverse.linear, Reverse.easeIn, Reverse.easeOut, Reverse.easeInOut, Reverse.easeOutIn)

Easing Demo:


[kml_flashembed fversion=”10.0.0″ movie=”http://www.taterboy.com/blog/flash/TweenSamples.swf” targetclass=”flashmovie” publishmethod=”static” width=”500″ height=”400″]

Get Adobe Flash player

[/kml_flashembed]

Visibility and Remove:
By default all tweened objects are made visible on frame one of a tween. You can override this functionality by adding startVisible:false to the extras.

//the object will not automatically turn visible on frame 1 of the tween
MoveThis.startTween(foo,{x:500},30,{startVisible:false});

MoveThis will also set the visible property to false after a tween is complete or remove that object from the display list. These two features are extremely effective ways to free up memory.

//the object's visible property will be set to false at the end of the tween.
MoveThis.startTween(foo,{x:500},30,{visible:false});

//the object will be removed from the display list on complete of the tween
MoveThis.startTween(foo,{x:500},30,{remove:true});

Pause and Stop:
Pause and Stop only work on tweens that currently exist in the MoveThis engine. You can make a call to MoveThis to pause or stop a particular tween or you can and stop all the existing tweens for a particular object.

//finds a tween for the object "foo" and the property "x"
MoveThis.stopTween(foo,"x");

//finds all tweens for the object "foo" and stops them
MoveThis.stopAllTweens(foo");

//pauses an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",true);

//resumes an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",false);

You can also pause MoveThis using MoveThis.pause(true);

Plugins:
Plugins are a great way to add functionality and new tween-able properties to objects. Included are a couple classes to animate the color or brightness of an object. Plugins can be installed at runtime.

var plugin:Object = {brightness: com.hdi.animate.Brightness};
MoveThis.install(plugin);

The installedPlugins property of MoveThis is an array of all the currently installed plugins.

var plugins:Array =  MoveThis.installedPlugins; // [returns an array or objects]

Working with Flex 4 SDK:
To use MoveThis with Flex 4's Group and Element classes, uncomment 3 snippets of code from com.hdi.animation.MoveThisEngine, to enable remove functionality. (sample snippet)

/***************************************************************
* FLEX 4 SDK: UNCOMMENT FOR Group and Element support (2 of 3)
***************************************************************/
/*
try{
moveObj.targetObj.parent.removeElement(moveObj.targetObj as IVisualElement);
}
catch(e:Error){}
*/
/*** END FLEX 4 SDK ********************************************/

UPDATE 1.20, 4/21/11 :

Updated code to run a little faster, using while loops instead of for each loops.
Added Sound or Mixer volume plugin to fade volume in and out.
Added methods for stopping queued animations

Download Complete Source Files

What tween engines do you like to use and why?

All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books';
echo '

';
echo getItem('0465050654', symptoms link 'taterboy-20');
echo '
';
echo getItem('0321980042','taterboy-20');
echo '
';
echo getItem('0941188108','taterboy-20');
echo '
';
echo getItem('1560100842','taterboy-20') . '

If you animate, learn the fundamentals.

';
echo '

';

echo '

Games

';
echo '

';
echo getItem('B01GP2070E','taterboy-20');
echo '
';
echo getItem('B00U1U34IE','taterboy-20');
echo '
';
echo getItem('B01GW3LR8M','taterboy-20');
echo '
';
echo getItem('B01GW3PAYE','taterboy-20');
echo '

';

UPDATE 1.20, troche 4/21/11 : new source files below

Animation is the primary reason our clients choose Flash based applications over HTML or any other language. Creating applications that dance is the "Rich" in RIA development.

Great animation or tween engines are plenty, GTween, TweenLite and Tweener are just a few. They provide a simpler way of animating with code. The Flash IDE team has also gone to great lengths to make working with animation in code easier for the designers. Even Flash Builder 4, which one could argue is a programmers tool, has new animation classes that are far more powerful than their predecessors.


Interactive Demos below...

Animation is what makes Flash, Flash:
MoveThis has been around in many different forms as my personal tween engine for the last 8 years. I think it's finally in a condition that it can be shared. The idea has always been one line of code to make something move, it's extremely simple to use, yet supports many great features.

This latest incarnation has focused on performance. Something that would work great for building mobile applications. It isn't perfect, or the only solution, but it works with my approach to building applications and games that require a great deal of animation.

Most tween engines work on the theory that a tween is something to keep around and run backwards and forwards, something like a video file with a play and pause function. MoveThis is based on an idea that there are so many tweens in an application, trying to manage pausing, reversing, playing and completion events gets too complicated or resource heavy.

Using MoveThis has 4 requirements:
1. know the display object to move.
2. know which property of the display object to animate.
3. know that target value of the display object property.
4. know how many frames the tween will span.

The resulting code looks like this:

MoveThis.startTween(foo,{x:500},30);

…which animates the x property of "foo" to a value of 500 over 30 frames. There are no start methods to call or instances to manage. Once the tween is complete it is nulled out and garbage collected.

Performance:
MoveThis is fairly light and very good on performance. MoveThis can run about 5000 tweens simultaneously at 24 frames per second and create *6500 new tweens in 1 second at 20 frames per second. MoveThis will add about 9k to your application.

*Note: One of the benefits of MoveThis is that it eliminates duplicate tweens, this constant cleaning can cause performance lags when adding a large amount ( > 250 ) of tweens on one frame. To get the type of performance claimed above, set ignoreDupes to true.

MoveThis.ignoreDupes = true;

Pros:
MoveThis uses 1 EventListener for all tweens, also onComplete, onStart and onFrame events use callbacks instead of Events which is better for mobile application performance. Optimized to work with thousands of tweens without worrying about duplicates or stopping tweens.

Cons:
Maybe not the best solution for a project with just a few animations that need to loop, stop, pause, play and rewind.

Now lets talk features!

Standard Features:
1. MoveThis is frame based, I have found that even the Timer class is not consistent from client to client based on processor speed, so we might as well use frames which is more accustom to animation. At some point I may add getTime and audio syncing.

2. onComplete, onStart, onFrame as callbacks instead of events, which preserves performance. Returns a references to the object being animated.

3. The pause tween: for when you want to call a function later, after a few frames, again without adding new events or timers.

4. visible = true: if something is animating, then it is probably meant to be seen, MoveThis automatically turns the visible property to true when the tween begins. (can be overridden)

5. One tween per object property at a time: This is one of the main reason MoveThis was created the way it was. Users changes there minds without waiting for tweens to complete. MoveThis will replace older, in progress tweens with a new one, picking up where the last tween left off.

6. Plugins: animate non-numeric properties, such as matrix, color, brightness, volume with custom plugins. (color and brightness plugins included)

7. queue tweens: when limiting one tween per property at a time, tweens can be queued for later, without overwriting a current tween. Just like startTween, except the first argument sets how many frames the tween will remain in the queue.

MoveThis.queueTween(30, foo,{x:500},30);

8. pause: pause a current tween or all tweens

9. stop an individual tween or stop all current tweens for each display object.

10. When a tween is completed it is nulled out, freeing up memory for other stuff.

11: based on standard easing functions: includes Reverse and Arch easing functions, as well as, standard easing functions by Robert Penner.

How it Works:
Arguments:
1. targObject: (Object) A reference to the object that is to be animated.
2. propValues: (Object) An object containing all the numeric properties or plugins of the object that are to be tweened.
3. frames: (int) The amount of frames the tweens will span.
4. extras: (Object) Many features such as onComplete, easingFunction, loop and delay are set in the extras object.

MoveThis.startTween(foo,{x:500},30,{onComplete:completeHandler,easing:"Sine.EaseIn",delay:30});


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/MoveThisDemo.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Extras (and how they work):
1. delay: (int) the frame count before the tween starts.

2. ease: (Number, 0 - 1) Adds an ease percentage to any easing function. designers like to add verity and subtlety to their animations, easing functions are no longer all or nothing.

3. easingFunction: (Function) Use standard or custom easing functions.

4. easing: (String, "Bounce.easeIn" ) Standard easing functions can be declared as a string, which elevates the need to import easing classes which helps in testing out a few different easing functions, trying to find that perfect ease.

5. loop: (Boolean) An animations can loop infinitely or just a few times.

6. visibility: (Boolean, false) Sets an object's visible property to false after a tween.

7. startVisible: (Boolean, false) Override the default behavior of automatically setting an object's visible property to true on the first frame of the tween.

8. remove: (Boolean) Automatically remove a display object or element after the tween is completed.

9. uid: (int ) A unique identifier, used for pause tweens, so they can be overwritten.

10. onStart, onFrame, onComplete: (Function) Callback functions, returns a reference to the animated object.

11. smartRotation: (Boolean) Forces the tween to rotate in the direction of the closest angle.

12. removeDupes: (Boolean, true) Default behavior is to remove all duplicates, but to save performance, you may want to turn this feature off and manage it on a per tween basis.

One Tween at a time:
Not to be stuck in an endless loop here, but this has a huge impact of how MoveThis is used, so one last time; I promise. Once a tween is completed in the MoveThis engine, it is removed and nulled out. If you need to reverse a tween or replay a previous tween, the best procedure is to start a new tween. MoveThis only allows one tween per property per object to occur at a time. If a tween is started on the x property of a displayObject named foo over 30 frames, when another tween is started just a few frames later for the same object's x property, the first tween will be replaced by the new tween. Once the new tween is finished, it will be removed forever, unless a loop count was added.

One Tween for each property:
When a tween is started, an object (MoveThisObject) is created for each property to be animated. Each tween object is then animated separately. This allows you to start one tween with multiple properties, then update the animation by starting a new tween with of single property value.

Example:

//initial tween
MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30);

//something in our app changes, that require foo to fade out.
MoveThis.startTween(foo,{alpha:0},30);

The x and y properties will continue to tween while the alpha property tween for foo will be replaced and the new fade out tween will began.

The repercussions are that if you have onComplete, onStart, onFrame callbacks assigned to that tween, the callbacks will be called for each property. In the following example, the function "completeHandler" will be called twice, once on complete of the x tween and once on the complete of the y tween.

Example:

MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30,{onComplete:completeHandler);

Three Ways to Make Things Happen Later:
1. delay: The simplest way to delay a tween.

//wait 20 frames before starting
MoveThis.startTween(foo,{x:500},30,{delay:20});

Note: If this is used and another tween is added for the x property of foo, it will be replaced, even if the delay has not expired

2. queueTween: When you know you want to move something later, but do not want it to overwrite a current tween.

//queue this tween for 30 frames
MoveThis.queueTween(30,foo,{x:500});

Note: Once the queue time is complete, the queued tween will replace any existing tweens for the same property of the same object.

3. The pause tween: Used when you want to call a function after a certain number of frames. Easier and requires less processor than using the Timer class.

//call pauseHandler after 90 frames.
MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler});

Note: Frame count is ignored. The pause tween must include an onComplete function.

Note: Replace null with a displayObject reference to have that reference sent to the onComplete function.

Unique ID: By default all pause tweens are persistent, meaning duplicates for the pause property are allowed to exist. If you need to overwrite a pause tween, then give the tween a unique id, when a new pause tween is created with the same id, it will overwrite the previous one.

MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler,uid:1});

[ad#content_banner]

onComplete Function Example:

function completeHandler(obj:Object):void{
//all target references are returned as objects.
//this allows you to start a new animation or modify the target when the animation is completed
if(obj != null)
obj.visible = false;
}

Easing:
Easing works very similar to all the existing tween/animation engines and works with any standardized easing functions. There are three ways to add eases to your animation.

1. easingFunction: This is the most typical ways of adding ease to a tween. Add a reference to any standardized easing function and you are done.

//add Sine.easeOut as the easingFunction. (the Sine.EaseOut class must be imported first)
MoveThis.startTween(foo,{x:500},30,{easingFunction:Sine.easeOut});

2. easing: An alternate method of #1 and for lazy people like me or someone that wants to try out a few different easing functions without importing them all. Enter one of the included standard tween function names as a string and MoveThis imports the correct easing function for you.

//add Sine.easeOut as the easingFunction without importing the class
MoveThis.startTween(foo,{x:500},30,{easing:"Sine.easeOut"});

3. easingStrength: Not every easing function has to be 100% all or nothing. Adding a 0 - 1 value will allow you to have a little less ease if needed.

//add Quart.easeOut as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{easing:"Quart.easeOut",easingStrength:0.6});

4. ease: Works just like the Flash IDE, set ease from -1 to 1 to automatically add Sine.easeOut or Sine.easeIn, depending on the value.

//add Sine.easeIn as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{ease:-0.6});

Note: There are two easing classes included to enable looping animations that reverse before looping again. (Arch.linear, Arch.easeIn, Arch.easeOut, Reverse.linear, Reverse.easeIn, Reverse.easeOut, Reverse.easeInOut, Reverse.easeOutIn)

Easing Demo:


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/TweenSamples.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Visibility and Remove:
By default all tweened objects are made visible on frame one of a tween. You can override this functionality by adding startVisible:false to the extras.

//the object will not automatically turn visible on frame 1 of the tween
MoveThis.startTween(foo,{x:500},30,{startVisible:false});

MoveThis will also set the visible property to false after a tween is complete or remove that object from the display list. These two features are extremely effective ways to free up memory.

//the object's visible property will be set to false at the end of the tween.
MoveThis.startTween(foo,{x:500},30,{visible:false});

//the object will be removed from the display list on complete of the tween
MoveThis.startTween(foo,{x:500},30,{remove:true});

Pause and Stop:
Pause and Stop only work on tweens that currently exist in the MoveThis engine. You can make a call to MoveThis to pause or stop a particular tween or you can and stop all the existing tweens for a particular object.

//finds a tween for the object "foo" and the property "x"
MoveThis.stopTween(foo,"x");

//finds all tweens for the object "foo" and stops them
MoveThis.stopAllTweens(foo");

//pauses an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",true);

//resumes an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",false);

You can also pause MoveThis using MoveThis.pause(true);

Plugins:
Plugins are a great way to add functionality and new tween-able properties to objects. Included are a couple classes to animate the color or brightness of an object. Plugins can be installed at runtime.

var plugin:Object = {brightness: com.hdi.animate.Brightness};
MoveThis.install(plugin);

The installedPlugins property of MoveThis is an array of all the currently installed plugins.

var plugins:Array =  MoveThis.installedPlugins; // [returns an array or objects]

Working with Flex 4 SDK:
To use MoveThis with Flex 4's Group and Element classes, uncomment 3 snippets of code from com.hdi.animation.MoveThisEngine, to enable remove functionality. (sample snippet)

/***************************************************************
* FLEX 4 SDK: UNCOMMENT FOR Group and Element support (2 of 3)
***************************************************************/
/*
try{
moveObj.targetObj.parent.removeElement(moveObj.targetObj as IVisualElement);
}
catch(e:Error){}
*/
/*** END FLEX 4 SDK ********************************************/

UPDATE 1.20, 4/21/11 :

Updated code to run a little faster, using while loops instead of for each loops.
Added Sound or Mixer volume plugin to fade volume in and out.
Added methods for stopping queued animations

Download Complete Source Files

What tween engines do you like to use and why?

AS3 Super Loader Part 2
This post is a continuation of the Action Script 3 Super Loader, find though this tip could have many adaptations besides the example below.

Many may already know that when you go to the Publish Settings/ HTML window, there is a drop-down that allows for the choice of HTML templates to use with your .swf. When Flash publishes the HTML page along with the .swf, it dynamically creates the new HTML file that will host your Flash movie, with the correct width, height, file name, background color of the .swf in the source code. Many developers use this HTML page to copy the embed code into another file. Some people ignore this feature all together and use Dreamweaver to produce the code or have a custom HTML template that they modify manually.

There are other options in this drop-down that include things like Flash version checking, scorm support, and SSL encryption. But the reality is, most of us would not use these files in a website or to show a client without at least a little modification. That is why we all probably have a few HTML templates of our own laying around.

Why not take those templates and make Flash HTML Templates, which is super easy. My default template has some custom css styles, javascript functions and centers the .swf on the page. I can use this HTML file to show development progress to a client.

I also have some custom scorm templates that work with a few different tracking systems. A lot of us use swfObject, you can even build a template that produces the correct code for swfObject on export. This may not be a huge time savings, but it is part of a smoother workflow.

This hint is about hooking up our Super Loader to an HTML template, but it should be enough information to build any kind of template.

First off, you should backup your existing HTML template files in case of any errors and more importantly, back up your custom templates in case a Flash update replaces them or a system crash. Plus you may want to share you templates or use them to standardize the workflow of your development team.

The templates are located in User Folder/Library/Application Support/Adobe/Flash CS3/en/Configuration/HTML/ on the mac, or C:Program FilesAdobeAdobe Flash CS3enConfiguration on the PC.

Inside the default.html file, you will see the script for embedding the .swf using AC_RunActiveContent. This script shows the best description of what most of the variables are.

Other Variables that are not well defined below:
$TT = the name that will show up in the drop down menu.
$DX, $DS, and $DF = flash version detection and the AC_RunActiveContent generation.
$CS = metedata tag
$PO = param tags for width, height, quality and color.
The rest is just HTML, so go crazy.

Modifying the Super Loader Stage class:
The first thing we need to do is modify the Super Stage class to allow for a dynamic source file, with a variable check.

class original source here.

[ad#content_banner]

package com.HDI.stage {
/*import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;*/
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;

public class SuperStage extends MovieClip {
//External Variables:
var fps:Number = 30;
/* remove the variable definition from swfURL*/
var swfURL:String;
var ldrURL:String = "loaderbar.swf";

//Loader Variables:
var loadComplete:Boolean = false;
var loadPerc:Number;
var loaderCnt:Number = 0;

//Internal Objects:
var mainMovie:Object;
var mainLdr:Object;
var mainContainer:MovieClip;
var loaderMC:MovieClip;

public function SuperStage():void{
init();
}
private function init():void{
/* Add variable check here and use a default swf name if swfURL does not exist.*/
if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}
//Set all the stage properties onload
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//load the main container and the loader container
/*
this is not manditory and can make things more complex,
but so that the loader always stays on top, I add these to MovieClips
then load everything else inside these clips.
Load the loaderMC second so that it remains on top.
*/
mainContainer = new MovieClip();
addChild(mainContainer);
loaderMC = new MovieClip();
addChild(loaderMC);

//setup stage init incase I need it later.
loaderInfo.addEventListener(Event.INIT,initStage);

//start to load the loader bar.
loadObject(loaderMC,ldrURL,null);
stop();
}
function initStage(ev:Event):void{
//stage.stageWidth = thisWidth;
//stage.stageHeight = thisHeight;
}
//main loader method
function loadObject(targ:Object,path:String,mon:Object):void{
var ldr:Loader = new Loader();
var ldrReq:URLRequest = new URLRequest(path);
ldr.load(ldrReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldrFin);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ldrProgress);
ldr.name = "ldr" + loaderCnt;
targ.addChild(ldr);
loaderCnt ++;
}
//finish loading. first two items loaded will be ldr0(loader bar) and ldr1(main content)
function ldrFin(ev:Event):void{
if(ev.target.loader.name == "ldr0"){
mainLdr = ev.target.content;
mainLdr.loadStat = true;
mainLdr.x = (stage.stageWidth/2)-(mainLdr.width/2);
mainLdr.y = (stage.stageHeight/2)-(mainLdr.height/2);
loadObject(mainContainer,swfURL,mainLdr);
}
else if(ev.target.loader.name == "ldr1"){
mainMovie = ev.target.content;
stage.frameRate = ev.target.frameRate;
}
}
//progress handler, sends loading info to loader bar.
function ldrProgress(ev:ProgressEvent):void{
if(mainLdr){
mainLdr.ldrMon(ev.bytesLoaded/ev.bytesTotal);
}
}
}
}

The rest happens in the HTML Template:
The new template is a modified copy of the default template.
It will set the stage swf as the source, then we will use flashVars to load in the current project name that will be used by the loader to display our current file.

$TTSuper Loader
$DXDefaultDetection.html
$DS
Display Adobe Flash Movies in HTML files updated for Active Content. NOTE: Publishing this template also creates AC_RunActiveContent.js in your HTML output folder which must be uploaded with the HTML.
$DF



$CS
$TI






$MU

$MT


©2008 taterboy, Inc. All Rights Reserved

Pretty Simple.
source

UPDATE

Updated the following code in "com/HDI/stage/SuperStage.as" so that the Loader will actually work with FlashVars. Also updated "FlashVars" in the HTML template code to have a capital "F". The source files have been updated as well.

if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}

All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books';
echo '

';
echo getItem('0465050654', symptoms link 'taterboy-20');
echo '
';
echo getItem('0321980042','taterboy-20');
echo '
';
echo getItem('0941188108','taterboy-20');
echo '
';
echo getItem('1560100842','taterboy-20') . '

If you animate, learn the fundamentals.

';
echo '

';

echo '

Games

';
echo '

';
echo getItem('B01GP2070E','taterboy-20');
echo '
';
echo getItem('B00U1U34IE','taterboy-20');
echo '
';
echo getItem('B01GW3LR8M','taterboy-20');
echo '
';
echo getItem('B01GW3PAYE','taterboy-20');
echo '

';

UPDATE 1.20, troche 4/21/11 : new source files below

Animation is the primary reason our clients choose Flash based applications over HTML or any other language. Creating applications that dance is the "Rich" in RIA development.

Great animation or tween engines are plenty, GTween, TweenLite and Tweener are just a few. They provide a simpler way of animating with code. The Flash IDE team has also gone to great lengths to make working with animation in code easier for the designers. Even Flash Builder 4, which one could argue is a programmers tool, has new animation classes that are far more powerful than their predecessors.


Interactive Demos below...

Animation is what makes Flash, Flash:
MoveThis has been around in many different forms as my personal tween engine for the last 8 years. I think it's finally in a condition that it can be shared. The idea has always been one line of code to make something move, it's extremely simple to use, yet supports many great features.

This latest incarnation has focused on performance. Something that would work great for building mobile applications. It isn't perfect, or the only solution, but it works with my approach to building applications and games that require a great deal of animation.

Most tween engines work on the theory that a tween is something to keep around and run backwards and forwards, something like a video file with a play and pause function. MoveThis is based on an idea that there are so many tweens in an application, trying to manage pausing, reversing, playing and completion events gets too complicated or resource heavy.

Using MoveThis has 4 requirements:
1. know the display object to move.
2. know which property of the display object to animate.
3. know that target value of the display object property.
4. know how many frames the tween will span.

The resulting code looks like this:

MoveThis.startTween(foo,{x:500},30);

…which animates the x property of "foo" to a value of 500 over 30 frames. There are no start methods to call or instances to manage. Once the tween is complete it is nulled out and garbage collected.

Performance:
MoveThis is fairly light and very good on performance. MoveThis can run about 5000 tweens simultaneously at 24 frames per second and create *6500 new tweens in 1 second at 20 frames per second. MoveThis will add about 9k to your application.

*Note: One of the benefits of MoveThis is that it eliminates duplicate tweens, this constant cleaning can cause performance lags when adding a large amount ( > 250 ) of tweens on one frame. To get the type of performance claimed above, set ignoreDupes to true.

MoveThis.ignoreDupes = true;

Pros:
MoveThis uses 1 EventListener for all tweens, also onComplete, onStart and onFrame events use callbacks instead of Events which is better for mobile application performance. Optimized to work with thousands of tweens without worrying about duplicates or stopping tweens.

Cons:
Maybe not the best solution for a project with just a few animations that need to loop, stop, pause, play and rewind.

Now lets talk features!

Standard Features:
1. MoveThis is frame based, I have found that even the Timer class is not consistent from client to client based on processor speed, so we might as well use frames which is more accustom to animation. At some point I may add getTime and audio syncing.

2. onComplete, onStart, onFrame as callbacks instead of events, which preserves performance. Returns a references to the object being animated.

3. The pause tween: for when you want to call a function later, after a few frames, again without adding new events or timers.

4. visible = true: if something is animating, then it is probably meant to be seen, MoveThis automatically turns the visible property to true when the tween begins. (can be overridden)

5. One tween per object property at a time: This is one of the main reason MoveThis was created the way it was. Users changes there minds without waiting for tweens to complete. MoveThis will replace older, in progress tweens with a new one, picking up where the last tween left off.

6. Plugins: animate non-numeric properties, such as matrix, color, brightness, volume with custom plugins. (color and brightness plugins included)

7. queue tweens: when limiting one tween per property at a time, tweens can be queued for later, without overwriting a current tween. Just like startTween, except the first argument sets how many frames the tween will remain in the queue.

MoveThis.queueTween(30, foo,{x:500},30);

8. pause: pause a current tween or all tweens

9. stop an individual tween or stop all current tweens for each display object.

10. When a tween is completed it is nulled out, freeing up memory for other stuff.

11: based on standard easing functions: includes Reverse and Arch easing functions, as well as, standard easing functions by Robert Penner.

How it Works:
Arguments:
1. targObject: (Object) A reference to the object that is to be animated.
2. propValues: (Object) An object containing all the numeric properties or plugins of the object that are to be tweened.
3. frames: (int) The amount of frames the tweens will span.
4. extras: (Object) Many features such as onComplete, easingFunction, loop and delay are set in the extras object.

MoveThis.startTween(foo,{x:500},30,{onComplete:completeHandler,easing:"Sine.EaseIn",delay:30});


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/MoveThisDemo.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Extras (and how they work):
1. delay: (int) the frame count before the tween starts.

2. ease: (Number, 0 - 1) Adds an ease percentage to any easing function. designers like to add verity and subtlety to their animations, easing functions are no longer all or nothing.

3. easingFunction: (Function) Use standard or custom easing functions.

4. easing: (String, "Bounce.easeIn" ) Standard easing functions can be declared as a string, which elevates the need to import easing classes which helps in testing out a few different easing functions, trying to find that perfect ease.

5. loop: (Boolean) An animations can loop infinitely or just a few times.

6. visibility: (Boolean, false) Sets an object's visible property to false after a tween.

7. startVisible: (Boolean, false) Override the default behavior of automatically setting an object's visible property to true on the first frame of the tween.

8. remove: (Boolean) Automatically remove a display object or element after the tween is completed.

9. uid: (int ) A unique identifier, used for pause tweens, so they can be overwritten.

10. onStart, onFrame, onComplete: (Function) Callback functions, returns a reference to the animated object.

11. smartRotation: (Boolean) Forces the tween to rotate in the direction of the closest angle.

12. removeDupes: (Boolean, true) Default behavior is to remove all duplicates, but to save performance, you may want to turn this feature off and manage it on a per tween basis.

One Tween at a time:
Not to be stuck in an endless loop here, but this has a huge impact of how MoveThis is used, so one last time; I promise. Once a tween is completed in the MoveThis engine, it is removed and nulled out. If you need to reverse a tween or replay a previous tween, the best procedure is to start a new tween. MoveThis only allows one tween per property per object to occur at a time. If a tween is started on the x property of a displayObject named foo over 30 frames, when another tween is started just a few frames later for the same object's x property, the first tween will be replaced by the new tween. Once the new tween is finished, it will be removed forever, unless a loop count was added.

One Tween for each property:
When a tween is started, an object (MoveThisObject) is created for each property to be animated. Each tween object is then animated separately. This allows you to start one tween with multiple properties, then update the animation by starting a new tween with of single property value.

Example:

//initial tween
MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30);

//something in our app changes, that require foo to fade out.
MoveThis.startTween(foo,{alpha:0},30);

The x and y properties will continue to tween while the alpha property tween for foo will be replaced and the new fade out tween will began.

The repercussions are that if you have onComplete, onStart, onFrame callbacks assigned to that tween, the callbacks will be called for each property. In the following example, the function "completeHandler" will be called twice, once on complete of the x tween and once on the complete of the y tween.

Example:

MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30,{onComplete:completeHandler);

Three Ways to Make Things Happen Later:
1. delay: The simplest way to delay a tween.

//wait 20 frames before starting
MoveThis.startTween(foo,{x:500},30,{delay:20});

Note: If this is used and another tween is added for the x property of foo, it will be replaced, even if the delay has not expired

2. queueTween: When you know you want to move something later, but do not want it to overwrite a current tween.

//queue this tween for 30 frames
MoveThis.queueTween(30,foo,{x:500});

Note: Once the queue time is complete, the queued tween will replace any existing tweens for the same property of the same object.

3. The pause tween: Used when you want to call a function after a certain number of frames. Easier and requires less processor than using the Timer class.

//call pauseHandler after 90 frames.
MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler});

Note: Frame count is ignored. The pause tween must include an onComplete function.

Note: Replace null with a displayObject reference to have that reference sent to the onComplete function.

Unique ID: By default all pause tweens are persistent, meaning duplicates for the pause property are allowed to exist. If you need to overwrite a pause tween, then give the tween a unique id, when a new pause tween is created with the same id, it will overwrite the previous one.

MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler,uid:1});

[ad#content_banner]

onComplete Function Example:

function completeHandler(obj:Object):void{
//all target references are returned as objects.
//this allows you to start a new animation or modify the target when the animation is completed
if(obj != null)
obj.visible = false;
}

Easing:
Easing works very similar to all the existing tween/animation engines and works with any standardized easing functions. There are three ways to add eases to your animation.

1. easingFunction: This is the most typical ways of adding ease to a tween. Add a reference to any standardized easing function and you are done.

//add Sine.easeOut as the easingFunction. (the Sine.EaseOut class must be imported first)
MoveThis.startTween(foo,{x:500},30,{easingFunction:Sine.easeOut});

2. easing: An alternate method of #1 and for lazy people like me or someone that wants to try out a few different easing functions without importing them all. Enter one of the included standard tween function names as a string and MoveThis imports the correct easing function for you.

//add Sine.easeOut as the easingFunction without importing the class
MoveThis.startTween(foo,{x:500},30,{easing:"Sine.easeOut"});

3. easingStrength: Not every easing function has to be 100% all or nothing. Adding a 0 - 1 value will allow you to have a little less ease if needed.

//add Quart.easeOut as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{easing:"Quart.easeOut",easingStrength:0.6});

4. ease: Works just like the Flash IDE, set ease from -1 to 1 to automatically add Sine.easeOut or Sine.easeIn, depending on the value.

//add Sine.easeIn as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{ease:-0.6});

Note: There are two easing classes included to enable looping animations that reverse before looping again. (Arch.linear, Arch.easeIn, Arch.easeOut, Reverse.linear, Reverse.easeIn, Reverse.easeOut, Reverse.easeInOut, Reverse.easeOutIn)

Easing Demo:


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/TweenSamples.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Visibility and Remove:
By default all tweened objects are made visible on frame one of a tween. You can override this functionality by adding startVisible:false to the extras.

//the object will not automatically turn visible on frame 1 of the tween
MoveThis.startTween(foo,{x:500},30,{startVisible:false});

MoveThis will also set the visible property to false after a tween is complete or remove that object from the display list. These two features are extremely effective ways to free up memory.

//the object's visible property will be set to false at the end of the tween.
MoveThis.startTween(foo,{x:500},30,{visible:false});

//the object will be removed from the display list on complete of the tween
MoveThis.startTween(foo,{x:500},30,{remove:true});

Pause and Stop:
Pause and Stop only work on tweens that currently exist in the MoveThis engine. You can make a call to MoveThis to pause or stop a particular tween or you can and stop all the existing tweens for a particular object.

//finds a tween for the object "foo" and the property "x"
MoveThis.stopTween(foo,"x");

//finds all tweens for the object "foo" and stops them
MoveThis.stopAllTweens(foo");

//pauses an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",true);

//resumes an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",false);

You can also pause MoveThis using MoveThis.pause(true);

Plugins:
Plugins are a great way to add functionality and new tween-able properties to objects. Included are a couple classes to animate the color or brightness of an object. Plugins can be installed at runtime.

var plugin:Object = {brightness: com.hdi.animate.Brightness};
MoveThis.install(plugin);

The installedPlugins property of MoveThis is an array of all the currently installed plugins.

var plugins:Array =  MoveThis.installedPlugins; // [returns an array or objects]

Working with Flex 4 SDK:
To use MoveThis with Flex 4's Group and Element classes, uncomment 3 snippets of code from com.hdi.animation.MoveThisEngine, to enable remove functionality. (sample snippet)

/***************************************************************
* FLEX 4 SDK: UNCOMMENT FOR Group and Element support (2 of 3)
***************************************************************/
/*
try{
moveObj.targetObj.parent.removeElement(moveObj.targetObj as IVisualElement);
}
catch(e:Error){}
*/
/*** END FLEX 4 SDK ********************************************/

UPDATE 1.20, 4/21/11 :

Updated code to run a little faster, using while loops instead of for each loops.
Added Sound or Mixer volume plugin to fade volume in and out.
Added methods for stopping queued animations

Download Complete Source Files

What tween engines do you like to use and why?

AS3 Super Loader Part 2
This post is a continuation of the Action Script 3 Super Loader, find though this tip could have many adaptations besides the example below.

Many may already know that when you go to the Publish Settings/ HTML window, there is a drop-down that allows for the choice of HTML templates to use with your .swf. When Flash publishes the HTML page along with the .swf, it dynamically creates the new HTML file that will host your Flash movie, with the correct width, height, file name, background color of the .swf in the source code. Many developers use this HTML page to copy the embed code into another file. Some people ignore this feature all together and use Dreamweaver to produce the code or have a custom HTML template that they modify manually.

There are other options in this drop-down that include things like Flash version checking, scorm support, and SSL encryption. But the reality is, most of us would not use these files in a website or to show a client without at least a little modification. That is why we all probably have a few HTML templates of our own laying around.

Why not take those templates and make Flash HTML Templates, which is super easy. My default template has some custom css styles, javascript functions and centers the .swf on the page. I can use this HTML file to show development progress to a client.

I also have some custom scorm templates that work with a few different tracking systems. A lot of us use swfObject, you can even build a template that produces the correct code for swfObject on export. This may not be a huge time savings, but it is part of a smoother workflow.

This hint is about hooking up our Super Loader to an HTML template, but it should be enough information to build any kind of template.

First off, you should backup your existing HTML template files in case of any errors and more importantly, back up your custom templates in case a Flash update replaces them or a system crash. Plus you may want to share you templates or use them to standardize the workflow of your development team.

The templates are located in User Folder/Library/Application Support/Adobe/Flash CS3/en/Configuration/HTML/ on the mac, or C:Program FilesAdobeAdobe Flash CS3enConfiguration on the PC.

Inside the default.html file, you will see the script for embedding the .swf using AC_RunActiveContent. This script shows the best description of what most of the variables are.

Other Variables that are not well defined below:
$TT = the name that will show up in the drop down menu.
$DX, $DS, and $DF = flash version detection and the AC_RunActiveContent generation.
$CS = metedata tag
$PO = param tags for width, height, quality and color.
The rest is just HTML, so go crazy.

Modifying the Super Loader Stage class:
The first thing we need to do is modify the Super Stage class to allow for a dynamic source file, with a variable check.

class original source here.

[ad#content_banner]

package com.HDI.stage {
/*import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;*/
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;

public class SuperStage extends MovieClip {
//External Variables:
var fps:Number = 30;
/* remove the variable definition from swfURL*/
var swfURL:String;
var ldrURL:String = "loaderbar.swf";

//Loader Variables:
var loadComplete:Boolean = false;
var loadPerc:Number;
var loaderCnt:Number = 0;

//Internal Objects:
var mainMovie:Object;
var mainLdr:Object;
var mainContainer:MovieClip;
var loaderMC:MovieClip;

public function SuperStage():void{
init();
}
private function init():void{
/* Add variable check here and use a default swf name if swfURL does not exist.*/
if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}
//Set all the stage properties onload
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//load the main container and the loader container
/*
this is not manditory and can make things more complex,
but so that the loader always stays on top, I add these to MovieClips
then load everything else inside these clips.
Load the loaderMC second so that it remains on top.
*/
mainContainer = new MovieClip();
addChild(mainContainer);
loaderMC = new MovieClip();
addChild(loaderMC);

//setup stage init incase I need it later.
loaderInfo.addEventListener(Event.INIT,initStage);

//start to load the loader bar.
loadObject(loaderMC,ldrURL,null);
stop();
}
function initStage(ev:Event):void{
//stage.stageWidth = thisWidth;
//stage.stageHeight = thisHeight;
}
//main loader method
function loadObject(targ:Object,path:String,mon:Object):void{
var ldr:Loader = new Loader();
var ldrReq:URLRequest = new URLRequest(path);
ldr.load(ldrReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldrFin);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ldrProgress);
ldr.name = "ldr" + loaderCnt;
targ.addChild(ldr);
loaderCnt ++;
}
//finish loading. first two items loaded will be ldr0(loader bar) and ldr1(main content)
function ldrFin(ev:Event):void{
if(ev.target.loader.name == "ldr0"){
mainLdr = ev.target.content;
mainLdr.loadStat = true;
mainLdr.x = (stage.stageWidth/2)-(mainLdr.width/2);
mainLdr.y = (stage.stageHeight/2)-(mainLdr.height/2);
loadObject(mainContainer,swfURL,mainLdr);
}
else if(ev.target.loader.name == "ldr1"){
mainMovie = ev.target.content;
stage.frameRate = ev.target.frameRate;
}
}
//progress handler, sends loading info to loader bar.
function ldrProgress(ev:ProgressEvent):void{
if(mainLdr){
mainLdr.ldrMon(ev.bytesLoaded/ev.bytesTotal);
}
}
}
}

The rest happens in the HTML Template:
The new template is a modified copy of the default template.
It will set the stage swf as the source, then we will use flashVars to load in the current project name that will be used by the loader to display our current file.

$TTSuper Loader
$DXDefaultDetection.html
$DS
Display Adobe Flash Movies in HTML files updated for Active Content. NOTE: Publishing this template also creates AC_RunActiveContent.js in your HTML output folder which must be uploaded with the HTML.
$DF



$CS
$TI






$MU

$MT


©2008 taterboy, Inc. All Rights Reserved

Pretty Simple.
source

UPDATE

Updated the following code in "com/HDI/stage/SuperStage.as" so that the Loader will actually work with FlashVars. Also updated "FlashVars" in the HTML template code to have a capital "F". The source files have been updated as well.

if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}

Here is an official geek badge for any Flash content. Not only does it display the loading percentage in binary, online it also has a dual knight Rider type pulsing effect. It was built a few years ago with high hopes of using it on something cool. I hope someone can find a cool home for it.

I am sure if I did not get the binary display just right someone will let me know, what is ed just be nice.

To use it, place it on the first frame of your flash file you need a loader for. also on that frame place a stop action and a function called imLoaded();

Here is an example.

// first frame, same as the loader component.
function imLoaded(){
gotoAndPlay(2);
}
stop();

[kml_flashembed movie="http://www.taterboy.com/blog/flash/BinaryLoader.swf" height="50" width="100" fversion="9" /]
Here is the FLA
All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books';
echo '

';
echo getItem('0465050654', symptoms link 'taterboy-20');
echo '
';
echo getItem('0321980042','taterboy-20');
echo '
';
echo getItem('0941188108','taterboy-20');
echo '
';
echo getItem('1560100842','taterboy-20') . '

If you animate, learn the fundamentals.

';
echo '

';

echo '

Games

';
echo '

';
echo getItem('B01GP2070E','taterboy-20');
echo '
';
echo getItem('B00U1U34IE','taterboy-20');
echo '
';
echo getItem('B01GW3LR8M','taterboy-20');
echo '
';
echo getItem('B01GW3PAYE','taterboy-20');
echo '

';

UPDATE 1.20, troche 4/21/11 : new source files below

Animation is the primary reason our clients choose Flash based applications over HTML or any other language. Creating applications that dance is the "Rich" in RIA development.

Great animation or tween engines are plenty, GTween, TweenLite and Tweener are just a few. They provide a simpler way of animating with code. The Flash IDE team has also gone to great lengths to make working with animation in code easier for the designers. Even Flash Builder 4, which one could argue is a programmers tool, has new animation classes that are far more powerful than their predecessors.


Interactive Demos below...

Animation is what makes Flash, Flash:
MoveThis has been around in many different forms as my personal tween engine for the last 8 years. I think it's finally in a condition that it can be shared. The idea has always been one line of code to make something move, it's extremely simple to use, yet supports many great features.

This latest incarnation has focused on performance. Something that would work great for building mobile applications. It isn't perfect, or the only solution, but it works with my approach to building applications and games that require a great deal of animation.

Most tween engines work on the theory that a tween is something to keep around and run backwards and forwards, something like a video file with a play and pause function. MoveThis is based on an idea that there are so many tweens in an application, trying to manage pausing, reversing, playing and completion events gets too complicated or resource heavy.

Using MoveThis has 4 requirements:
1. know the display object to move.
2. know which property of the display object to animate.
3. know that target value of the display object property.
4. know how many frames the tween will span.

The resulting code looks like this:

MoveThis.startTween(foo,{x:500},30);

…which animates the x property of "foo" to a value of 500 over 30 frames. There are no start methods to call or instances to manage. Once the tween is complete it is nulled out and garbage collected.

Performance:
MoveThis is fairly light and very good on performance. MoveThis can run about 5000 tweens simultaneously at 24 frames per second and create *6500 new tweens in 1 second at 20 frames per second. MoveThis will add about 9k to your application.

*Note: One of the benefits of MoveThis is that it eliminates duplicate tweens, this constant cleaning can cause performance lags when adding a large amount ( > 250 ) of tweens on one frame. To get the type of performance claimed above, set ignoreDupes to true.

MoveThis.ignoreDupes = true;

Pros:
MoveThis uses 1 EventListener for all tweens, also onComplete, onStart and onFrame events use callbacks instead of Events which is better for mobile application performance. Optimized to work with thousands of tweens without worrying about duplicates or stopping tweens.

Cons:
Maybe not the best solution for a project with just a few animations that need to loop, stop, pause, play and rewind.

Now lets talk features!

Standard Features:
1. MoveThis is frame based, I have found that even the Timer class is not consistent from client to client based on processor speed, so we might as well use frames which is more accustom to animation. At some point I may add getTime and audio syncing.

2. onComplete, onStart, onFrame as callbacks instead of events, which preserves performance. Returns a references to the object being animated.

3. The pause tween: for when you want to call a function later, after a few frames, again without adding new events or timers.

4. visible = true: if something is animating, then it is probably meant to be seen, MoveThis automatically turns the visible property to true when the tween begins. (can be overridden)

5. One tween per object property at a time: This is one of the main reason MoveThis was created the way it was. Users changes there minds without waiting for tweens to complete. MoveThis will replace older, in progress tweens with a new one, picking up where the last tween left off.

6. Plugins: animate non-numeric properties, such as matrix, color, brightness, volume with custom plugins. (color and brightness plugins included)

7. queue tweens: when limiting one tween per property at a time, tweens can be queued for later, without overwriting a current tween. Just like startTween, except the first argument sets how many frames the tween will remain in the queue.

MoveThis.queueTween(30, foo,{x:500},30);

8. pause: pause a current tween or all tweens

9. stop an individual tween or stop all current tweens for each display object.

10. When a tween is completed it is nulled out, freeing up memory for other stuff.

11: based on standard easing functions: includes Reverse and Arch easing functions, as well as, standard easing functions by Robert Penner.

How it Works:
Arguments:
1. targObject: (Object) A reference to the object that is to be animated.
2. propValues: (Object) An object containing all the numeric properties or plugins of the object that are to be tweened.
3. frames: (int) The amount of frames the tweens will span.
4. extras: (Object) Many features such as onComplete, easingFunction, loop and delay are set in the extras object.

MoveThis.startTween(foo,{x:500},30,{onComplete:completeHandler,easing:"Sine.EaseIn",delay:30});


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/MoveThisDemo.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Extras (and how they work):
1. delay: (int) the frame count before the tween starts.

2. ease: (Number, 0 - 1) Adds an ease percentage to any easing function. designers like to add verity and subtlety to their animations, easing functions are no longer all or nothing.

3. easingFunction: (Function) Use standard or custom easing functions.

4. easing: (String, "Bounce.easeIn" ) Standard easing functions can be declared as a string, which elevates the need to import easing classes which helps in testing out a few different easing functions, trying to find that perfect ease.

5. loop: (Boolean) An animations can loop infinitely or just a few times.

6. visibility: (Boolean, false) Sets an object's visible property to false after a tween.

7. startVisible: (Boolean, false) Override the default behavior of automatically setting an object's visible property to true on the first frame of the tween.

8. remove: (Boolean) Automatically remove a display object or element after the tween is completed.

9. uid: (int ) A unique identifier, used for pause tweens, so they can be overwritten.

10. onStart, onFrame, onComplete: (Function) Callback functions, returns a reference to the animated object.

11. smartRotation: (Boolean) Forces the tween to rotate in the direction of the closest angle.

12. removeDupes: (Boolean, true) Default behavior is to remove all duplicates, but to save performance, you may want to turn this feature off and manage it on a per tween basis.

One Tween at a time:
Not to be stuck in an endless loop here, but this has a huge impact of how MoveThis is used, so one last time; I promise. Once a tween is completed in the MoveThis engine, it is removed and nulled out. If you need to reverse a tween or replay a previous tween, the best procedure is to start a new tween. MoveThis only allows one tween per property per object to occur at a time. If a tween is started on the x property of a displayObject named foo over 30 frames, when another tween is started just a few frames later for the same object's x property, the first tween will be replaced by the new tween. Once the new tween is finished, it will be removed forever, unless a loop count was added.

One Tween for each property:
When a tween is started, an object (MoveThisObject) is created for each property to be animated. Each tween object is then animated separately. This allows you to start one tween with multiple properties, then update the animation by starting a new tween with of single property value.

Example:

//initial tween
MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30);

//something in our app changes, that require foo to fade out.
MoveThis.startTween(foo,{alpha:0},30);

The x and y properties will continue to tween while the alpha property tween for foo will be replaced and the new fade out tween will began.

The repercussions are that if you have onComplete, onStart, onFrame callbacks assigned to that tween, the callbacks will be called for each property. In the following example, the function "completeHandler" will be called twice, once on complete of the x tween and once on the complete of the y tween.

Example:

MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30,{onComplete:completeHandler);

Three Ways to Make Things Happen Later:
1. delay: The simplest way to delay a tween.

//wait 20 frames before starting
MoveThis.startTween(foo,{x:500},30,{delay:20});

Note: If this is used and another tween is added for the x property of foo, it will be replaced, even if the delay has not expired

2. queueTween: When you know you want to move something later, but do not want it to overwrite a current tween.

//queue this tween for 30 frames
MoveThis.queueTween(30,foo,{x:500});

Note: Once the queue time is complete, the queued tween will replace any existing tweens for the same property of the same object.

3. The pause tween: Used when you want to call a function after a certain number of frames. Easier and requires less processor than using the Timer class.

//call pauseHandler after 90 frames.
MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler});

Note: Frame count is ignored. The pause tween must include an onComplete function.

Note: Replace null with a displayObject reference to have that reference sent to the onComplete function.

Unique ID: By default all pause tweens are persistent, meaning duplicates for the pause property are allowed to exist. If you need to overwrite a pause tween, then give the tween a unique id, when a new pause tween is created with the same id, it will overwrite the previous one.

MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler,uid:1});

[ad#content_banner]

onComplete Function Example:

function completeHandler(obj:Object):void{
//all target references are returned as objects.
//this allows you to start a new animation or modify the target when the animation is completed
if(obj != null)
obj.visible = false;
}

Easing:
Easing works very similar to all the existing tween/animation engines and works with any standardized easing functions. There are three ways to add eases to your animation.

1. easingFunction: This is the most typical ways of adding ease to a tween. Add a reference to any standardized easing function and you are done.

//add Sine.easeOut as the easingFunction. (the Sine.EaseOut class must be imported first)
MoveThis.startTween(foo,{x:500},30,{easingFunction:Sine.easeOut});

2. easing: An alternate method of #1 and for lazy people like me or someone that wants to try out a few different easing functions without importing them all. Enter one of the included standard tween function names as a string and MoveThis imports the correct easing function for you.

//add Sine.easeOut as the easingFunction without importing the class
MoveThis.startTween(foo,{x:500},30,{easing:"Sine.easeOut"});

3. easingStrength: Not every easing function has to be 100% all or nothing. Adding a 0 - 1 value will allow you to have a little less ease if needed.

//add Quart.easeOut as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{easing:"Quart.easeOut",easingStrength:0.6});

4. ease: Works just like the Flash IDE, set ease from -1 to 1 to automatically add Sine.easeOut or Sine.easeIn, depending on the value.

//add Sine.easeIn as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{ease:-0.6});

Note: There are two easing classes included to enable looping animations that reverse before looping again. (Arch.linear, Arch.easeIn, Arch.easeOut, Reverse.linear, Reverse.easeIn, Reverse.easeOut, Reverse.easeInOut, Reverse.easeOutIn)

Easing Demo:


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/TweenSamples.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Visibility and Remove:
By default all tweened objects are made visible on frame one of a tween. You can override this functionality by adding startVisible:false to the extras.

//the object will not automatically turn visible on frame 1 of the tween
MoveThis.startTween(foo,{x:500},30,{startVisible:false});

MoveThis will also set the visible property to false after a tween is complete or remove that object from the display list. These two features are extremely effective ways to free up memory.

//the object's visible property will be set to false at the end of the tween.
MoveThis.startTween(foo,{x:500},30,{visible:false});

//the object will be removed from the display list on complete of the tween
MoveThis.startTween(foo,{x:500},30,{remove:true});

Pause and Stop:
Pause and Stop only work on tweens that currently exist in the MoveThis engine. You can make a call to MoveThis to pause or stop a particular tween or you can and stop all the existing tweens for a particular object.

//finds a tween for the object "foo" and the property "x"
MoveThis.stopTween(foo,"x");

//finds all tweens for the object "foo" and stops them
MoveThis.stopAllTweens(foo");

//pauses an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",true);

//resumes an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",false);

You can also pause MoveThis using MoveThis.pause(true);

Plugins:
Plugins are a great way to add functionality and new tween-able properties to objects. Included are a couple classes to animate the color or brightness of an object. Plugins can be installed at runtime.

var plugin:Object = {brightness: com.hdi.animate.Brightness};
MoveThis.install(plugin);

The installedPlugins property of MoveThis is an array of all the currently installed plugins.

var plugins:Array =  MoveThis.installedPlugins; // [returns an array or objects]

Working with Flex 4 SDK:
To use MoveThis with Flex 4's Group and Element classes, uncomment 3 snippets of code from com.hdi.animation.MoveThisEngine, to enable remove functionality. (sample snippet)

/***************************************************************
* FLEX 4 SDK: UNCOMMENT FOR Group and Element support (2 of 3)
***************************************************************/
/*
try{
moveObj.targetObj.parent.removeElement(moveObj.targetObj as IVisualElement);
}
catch(e:Error){}
*/
/*** END FLEX 4 SDK ********************************************/

UPDATE 1.20, 4/21/11 :

Updated code to run a little faster, using while loops instead of for each loops.
Added Sound or Mixer volume plugin to fade volume in and out.
Added methods for stopping queued animations

Download Complete Source Files

What tween engines do you like to use and why?

AS3 Super Loader Part 2
This post is a continuation of the Action Script 3 Super Loader, find though this tip could have many adaptations besides the example below.

Many may already know that when you go to the Publish Settings/ HTML window, there is a drop-down that allows for the choice of HTML templates to use with your .swf. When Flash publishes the HTML page along with the .swf, it dynamically creates the new HTML file that will host your Flash movie, with the correct width, height, file name, background color of the .swf in the source code. Many developers use this HTML page to copy the embed code into another file. Some people ignore this feature all together and use Dreamweaver to produce the code or have a custom HTML template that they modify manually.

There are other options in this drop-down that include things like Flash version checking, scorm support, and SSL encryption. But the reality is, most of us would not use these files in a website or to show a client without at least a little modification. That is why we all probably have a few HTML templates of our own laying around.

Why not take those templates and make Flash HTML Templates, which is super easy. My default template has some custom css styles, javascript functions and centers the .swf on the page. I can use this HTML file to show development progress to a client.

I also have some custom scorm templates that work with a few different tracking systems. A lot of us use swfObject, you can even build a template that produces the correct code for swfObject on export. This may not be a huge time savings, but it is part of a smoother workflow.

This hint is about hooking up our Super Loader to an HTML template, but it should be enough information to build any kind of template.

First off, you should backup your existing HTML template files in case of any errors and more importantly, back up your custom templates in case a Flash update replaces them or a system crash. Plus you may want to share you templates or use them to standardize the workflow of your development team.

The templates are located in User Folder/Library/Application Support/Adobe/Flash CS3/en/Configuration/HTML/ on the mac, or C:Program FilesAdobeAdobe Flash CS3enConfiguration on the PC.

Inside the default.html file, you will see the script for embedding the .swf using AC_RunActiveContent. This script shows the best description of what most of the variables are.

Other Variables that are not well defined below:
$TT = the name that will show up in the drop down menu.
$DX, $DS, and $DF = flash version detection and the AC_RunActiveContent generation.
$CS = metedata tag
$PO = param tags for width, height, quality and color.
The rest is just HTML, so go crazy.

Modifying the Super Loader Stage class:
The first thing we need to do is modify the Super Stage class to allow for a dynamic source file, with a variable check.

class original source here.

[ad#content_banner]

package com.HDI.stage {
/*import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;*/
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;

public class SuperStage extends MovieClip {
//External Variables:
var fps:Number = 30;
/* remove the variable definition from swfURL*/
var swfURL:String;
var ldrURL:String = "loaderbar.swf";

//Loader Variables:
var loadComplete:Boolean = false;
var loadPerc:Number;
var loaderCnt:Number = 0;

//Internal Objects:
var mainMovie:Object;
var mainLdr:Object;
var mainContainer:MovieClip;
var loaderMC:MovieClip;

public function SuperStage():void{
init();
}
private function init():void{
/* Add variable check here and use a default swf name if swfURL does not exist.*/
if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}
//Set all the stage properties onload
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//load the main container and the loader container
/*
this is not manditory and can make things more complex,
but so that the loader always stays on top, I add these to MovieClips
then load everything else inside these clips.
Load the loaderMC second so that it remains on top.
*/
mainContainer = new MovieClip();
addChild(mainContainer);
loaderMC = new MovieClip();
addChild(loaderMC);

//setup stage init incase I need it later.
loaderInfo.addEventListener(Event.INIT,initStage);

//start to load the loader bar.
loadObject(loaderMC,ldrURL,null);
stop();
}
function initStage(ev:Event):void{
//stage.stageWidth = thisWidth;
//stage.stageHeight = thisHeight;
}
//main loader method
function loadObject(targ:Object,path:String,mon:Object):void{
var ldr:Loader = new Loader();
var ldrReq:URLRequest = new URLRequest(path);
ldr.load(ldrReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldrFin);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ldrProgress);
ldr.name = "ldr" + loaderCnt;
targ.addChild(ldr);
loaderCnt ++;
}
//finish loading. first two items loaded will be ldr0(loader bar) and ldr1(main content)
function ldrFin(ev:Event):void{
if(ev.target.loader.name == "ldr0"){
mainLdr = ev.target.content;
mainLdr.loadStat = true;
mainLdr.x = (stage.stageWidth/2)-(mainLdr.width/2);
mainLdr.y = (stage.stageHeight/2)-(mainLdr.height/2);
loadObject(mainContainer,swfURL,mainLdr);
}
else if(ev.target.loader.name == "ldr1"){
mainMovie = ev.target.content;
stage.frameRate = ev.target.frameRate;
}
}
//progress handler, sends loading info to loader bar.
function ldrProgress(ev:ProgressEvent):void{
if(mainLdr){
mainLdr.ldrMon(ev.bytesLoaded/ev.bytesTotal);
}
}
}
}

The rest happens in the HTML Template:
The new template is a modified copy of the default template.
It will set the stage swf as the source, then we will use flashVars to load in the current project name that will be used by the loader to display our current file.

$TTSuper Loader
$DXDefaultDetection.html
$DS
Display Adobe Flash Movies in HTML files updated for Active Content. NOTE: Publishing this template also creates AC_RunActiveContent.js in your HTML output folder which must be uploaded with the HTML.
$DF



$CS
$TI






$MU

$MT


©2008 taterboy, Inc. All Rights Reserved

Pretty Simple.
source

UPDATE

Updated the following code in "com/HDI/stage/SuperStage.as" so that the Loader will actually work with FlashVars. Also updated "FlashVars" in the HTML template code to have a capital "F". The source files have been updated as well.

if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}

Here is an official geek badge for any Flash content. Not only does it display the loading percentage in binary, online it also has a dual knight Rider type pulsing effect. It was built a few years ago with high hopes of using it on something cool. I hope someone can find a cool home for it.

I am sure if I did not get the binary display just right someone will let me know, what is ed just be nice.

To use it, place it on the first frame of your flash file you need a loader for. also on that frame place a stop action and a function called imLoaded();

Here is an example.

// first frame, same as the loader component.
function imLoaded(){
gotoAndPlay(2);
}
stop();

[kml_flashembed movie="http://www.taterboy.com/blog/flash/BinaryLoader.swf" height="50" width="100" fversion="9" /]
Here is the FLA
With the nature of vectors being smaller than bitmap images in file size, more about I typically try to illustrate everything I do for Flash in Illustrator first. I love Illustrator as an illustration tool. Although Flash has made some great progress it's illustration tool set, discount it just does not come close to the power and features of Illustrator. I also find Illustrator really fast for laying out design projects and more illustrative graphics then modeling and detailing in photoshop. Like any relationship, viagra 60mg my affection for illustrator is not without frustration and we have to learn to accept some of the faults, if you can pardon my Dr. Phil type metaphor, to make it work. So here are some workarounds for some illustrator issues and a couple tips to help you work better with this great tool.


1. New Document Profiles:
Tired of deleting all the colors, brushes and symbols every time you create a new Illustrator document? Sick of making a new template because you accidentally saved over that last one? Illustrator uses Template files for each document profile. Those template files are standard .ai files so you can edit the source of each profile with ease. By deleting all those colors, brushes, and symbols out of these template files, all the new documents you create will only contain the elements and setting you want. You can even create new profiles.
On a Mac they are located in the Library/Application Support/Adobe/Adobe Illustrator CS3/New Document Profiles folder.
On the PC look in Documents and Settings /*User Name*/Application Data/Adobe/Adobe Illustrator CS3 Settings/New Document Profiles/


default swatches
default brushes
default symbols

If you add a new file, it will show up in the profile drop down of the new file dialog box.

[ad#content_banner]

2. Free Transform Tool (works the same way in Photoshop and Flash):
This is one of the most powerful tools in the tools palette. If you can imagine the Oxy Clean guy going on about this tool, that's how great it is.
The real power comes in the form of augmenting it's functionality with keyboard keys. After selecting a node of the free transform tool bounding box, add the following keys to change its behavior. ***The key is to select a node first, then adding the extra keys. These special keys are:
Shift: Constrains scaling to the original aspect ratio, rotation to 45 degrees, free distort to limited angles, and skew to current height or width.
Command (Ctrl PC): Free distort of corner or side. Works well for mapping and tweaking flat artwork onto a plane in perspective.
Command + Option (Ctrl + Alt PC): Skewing
Command + Option + Shift (Ctrl + Alt + Shift PC): Shear, takes an object and lays it back in perspective.

Free Transform

3. Nudging artwork with the arrow keys:
On some older machines this seems to be more of an issue. When you nudge selected items around the art board, sometimes you do not see the results for a second or two. Normally, it happens with large complex artwork. I find that if I tap Shift, Command (Ctrl), or Space bar, the screen refreshes and I can see the results a lot faster. Holding the Shift key while you nudge is like a 10x nudge. To clarify, 10 normal arrow only nudges equal 1 shift + arrow nudge.

4. PathFinder divide and unite:
There are two buttons in the Pathfinder Palette that I use the most, Divide and Unite. From the old days of spot color separations, I have been trained to keep my artwork as clean as possible. This is also important if you want to animate vector artwork and make sure it does not blow up when you bring it over to Flash. Uniting shapes that have the same color helps to keep your artwork organized and clean.
Pathfinder is a huge timesaver while illustrating. The less lines you have to put down saves time. Especially if those extra lines are tracing existing lines. I will give an illustration tutorial and go over this technique in greater detail. But here is a simple tip for now. If you have a single shape that you want to fill with two different colors, do not draw another shape, copy the original and divide it.
In the example below:

Unite and Divide

A. shows a shape, with it selected, copy & paste in front. Draw a path, select the top copy and the new path & divide. Delete the top half.
B. shows the original shape with a 6 point stroke. Select the original shape, copy & paste behind. Add the 6 point stroke, expand and unite. *for best results, change the gradient to a solid color before expanding.
C. Shows the final button. The benefits of this technique are: 1. I can modify the the bottom shadow shape, like adding an arch or wave without having to match it with a top shape. 2. We preserve the original shape for easier editing later. 3. very clean artwork.

5. Align & Average:
If you ever spend more then a second wondering if something is centered, you are wasting time. Open that align palette and force those objects to be centered, justified or spaced out evenly. Nothing looks worse then artwork that is so close to being aligned, but just a tad off. Align only works on items that are ungrouped or multiple groups.
Average is like align, but only works on path nodes. Sometimes while illustrating a line, it takes a second or two to get a line perfectly straight. Just select the two nodes and use the Average dialog ( Command + Option + J mac) (Ctrl + Alt + J PC) and choose horizontal or vertical. and they will straighten right up.


Align palette
Average Dialog

6. Selection preferences. Arrows and Type:
By default the preference (Selection & Anchor Display) for "Object Selection By Path Only" is not checked, meaning you can select an object by clicking anywhere on the object face. You can select items underneath by toggling preview to wireframe (Command + Y or Ctrl + Y). By enabling this feature, you will be able to select shapes without toggling Preview, hiding or locking other objects, which will make you more efficient. It may take some getting used to if you have been using the default setting all along. Likewise, there is a preference for "Type Object Selection By Path Only", which is disabled by default. Enabling it will allow you to select paths behind or around text.

Selection Prefs

7. Colors and swatches:
I would like to do a whole post on color swatches and illustration soon, but until then, color swatches can be your friend. I do not mean the ones that are in the swatches palette when you open a new document. If you read the earlier tip, we should be rid of them by now. Making a custom color palette based on mood, branding or whatever you want to communicate is scores better than making up colors on the fly or picking colors because they just happen to be in the color palette. Most computers can display 16 million colors telling us there are a many more Hughes of green then the lime and forest green in the default color palette. Saving colors to swatches saves us from trying to make the same color over and over. Saving colors as spot color is cool for certain printing jobs and if you ever want to update a color, you can do it one time and every object filled or stoked with that color will be updated as well. The down side is spot colors make horrible gradients. I normally stick with RGB swatches and use Select Same Fill or Stroke Color to update colors if that arrises. Also, if you have an illustrator file with a a bunch of swatches and you need them in a new illustrator document. You can use Window/Swatch Libraries/Other library and a new swatch pallet will appear with the needed swatches from the Previous Illustrator file.


New Colors

8. Actions (same in Photoshop):
Actions are the coolest thing since Command + Z (Ctrl + Z PC). There are certain combinations of tasks that I perform at least 50 times or more in a single illustration. I make actions of those combos and assign an F key to it. This saves tons of time. My most use actions are probably Expand + Unite, which merges the stoke and fill into one shape. The other is Place just because there is not a default keyboard shortcut for that menu item. I also use actions for special transforms that I will have to do more then once or we can build template files with actions so that anyone with illustrator or Photoshop can recreate the transforms to match the original. ** The most important thing to know about actions is saving them. I keep apps open for weeks at a time. Any crash during that time will erase any actions you have created.

9. Just say no to strokes:
One of the most time consuming things about Flash development is fixing artwork imported from illustrator. With CS3 that chore has been greatly reduced, but there are still a few things that still do not translate the same. Strokes are a large contributer to some vector artwork in flash looking terrible. If you try to Convert Stokes to Fills in Flash, many times most of the stroke will just disappear. It is best to do all that in Illustrator using the previous tip, as well as some good planning to keep your artwork clean. There are some good reasons to use strokes in Flash, otherwise getting rid of them in Illustrator will make life much easier and your graphics looking better.

Cleanup Strokes

10. Grouping:
One of the reasons Illustrator is so much more efficient then photoshop for comping up rough layouts is that you do not need to know what layer the artwork is on to move or transform it. You just select the artwork directly and transform away. Using groups wisely will diminish the amount of time it takes to make selections. Once an section of an illustration is complete, you should make it into a group. The next time you need to transform that group, it is only one click away. Using the Command + Option + Tab (Ctrl + Alt + Tab PC) to toggle the open and closed arrow selections tools will make the different types of selections happen a lot quicker. Also Command + Option + Double-Click (Ctrl + Alt + Double-Click PC) with the open arrow selection tool will select a sub-ground within a group. Another click will add the whole group to the selection.

All the items on this page are things that I own and have benefitted my work and/or relaxation.

Note: The prices below are pulled directly from Amazon (New starting price) and may not reflect the best price or current deals currently available. Click on an item to go directly to Amazon.com

Books';
echo '

';
echo getItem('0465050654', symptoms link 'taterboy-20');
echo '
';
echo getItem('0321980042','taterboy-20');
echo '
';
echo getItem('0941188108','taterboy-20');
echo '
';
echo getItem('1560100842','taterboy-20') . '

If you animate, learn the fundamentals.

';
echo '

';

echo '

Games

';
echo '

';
echo getItem('B01GP2070E','taterboy-20');
echo '
';
echo getItem('B00U1U34IE','taterboy-20');
echo '
';
echo getItem('B01GW3LR8M','taterboy-20');
echo '
';
echo getItem('B01GW3PAYE','taterboy-20');
echo '

';

UPDATE 1.20, troche 4/21/11 : new source files below

Animation is the primary reason our clients choose Flash based applications over HTML or any other language. Creating applications that dance is the "Rich" in RIA development.

Great animation or tween engines are plenty, GTween, TweenLite and Tweener are just a few. They provide a simpler way of animating with code. The Flash IDE team has also gone to great lengths to make working with animation in code easier for the designers. Even Flash Builder 4, which one could argue is a programmers tool, has new animation classes that are far more powerful than their predecessors.


Interactive Demos below...

Animation is what makes Flash, Flash:
MoveThis has been around in many different forms as my personal tween engine for the last 8 years. I think it's finally in a condition that it can be shared. The idea has always been one line of code to make something move, it's extremely simple to use, yet supports many great features.

This latest incarnation has focused on performance. Something that would work great for building mobile applications. It isn't perfect, or the only solution, but it works with my approach to building applications and games that require a great deal of animation.

Most tween engines work on the theory that a tween is something to keep around and run backwards and forwards, something like a video file with a play and pause function. MoveThis is based on an idea that there are so many tweens in an application, trying to manage pausing, reversing, playing and completion events gets too complicated or resource heavy.

Using MoveThis has 4 requirements:
1. know the display object to move.
2. know which property of the display object to animate.
3. know that target value of the display object property.
4. know how many frames the tween will span.

The resulting code looks like this:

MoveThis.startTween(foo,{x:500},30);

…which animates the x property of "foo" to a value of 500 over 30 frames. There are no start methods to call or instances to manage. Once the tween is complete it is nulled out and garbage collected.

Performance:
MoveThis is fairly light and very good on performance. MoveThis can run about 5000 tweens simultaneously at 24 frames per second and create *6500 new tweens in 1 second at 20 frames per second. MoveThis will add about 9k to your application.

*Note: One of the benefits of MoveThis is that it eliminates duplicate tweens, this constant cleaning can cause performance lags when adding a large amount ( > 250 ) of tweens on one frame. To get the type of performance claimed above, set ignoreDupes to true.

MoveThis.ignoreDupes = true;

Pros:
MoveThis uses 1 EventListener for all tweens, also onComplete, onStart and onFrame events use callbacks instead of Events which is better for mobile application performance. Optimized to work with thousands of tweens without worrying about duplicates or stopping tweens.

Cons:
Maybe not the best solution for a project with just a few animations that need to loop, stop, pause, play and rewind.

Now lets talk features!

Standard Features:
1. MoveThis is frame based, I have found that even the Timer class is not consistent from client to client based on processor speed, so we might as well use frames which is more accustom to animation. At some point I may add getTime and audio syncing.

2. onComplete, onStart, onFrame as callbacks instead of events, which preserves performance. Returns a references to the object being animated.

3. The pause tween: for when you want to call a function later, after a few frames, again without adding new events or timers.

4. visible = true: if something is animating, then it is probably meant to be seen, MoveThis automatically turns the visible property to true when the tween begins. (can be overridden)

5. One tween per object property at a time: This is one of the main reason MoveThis was created the way it was. Users changes there minds without waiting for tweens to complete. MoveThis will replace older, in progress tweens with a new one, picking up where the last tween left off.

6. Plugins: animate non-numeric properties, such as matrix, color, brightness, volume with custom plugins. (color and brightness plugins included)

7. queue tweens: when limiting one tween per property at a time, tweens can be queued for later, without overwriting a current tween. Just like startTween, except the first argument sets how many frames the tween will remain in the queue.

MoveThis.queueTween(30, foo,{x:500},30);

8. pause: pause a current tween or all tweens

9. stop an individual tween or stop all current tweens for each display object.

10. When a tween is completed it is nulled out, freeing up memory for other stuff.

11: based on standard easing functions: includes Reverse and Arch easing functions, as well as, standard easing functions by Robert Penner.

How it Works:
Arguments:
1. targObject: (Object) A reference to the object that is to be animated.
2. propValues: (Object) An object containing all the numeric properties or plugins of the object that are to be tweened.
3. frames: (int) The amount of frames the tweens will span.
4. extras: (Object) Many features such as onComplete, easingFunction, loop and delay are set in the extras object.

MoveThis.startTween(foo,{x:500},30,{onComplete:completeHandler,easing:"Sine.EaseIn",delay:30});


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/MoveThisDemo.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Extras (and how they work):
1. delay: (int) the frame count before the tween starts.

2. ease: (Number, 0 - 1) Adds an ease percentage to any easing function. designers like to add verity and subtlety to their animations, easing functions are no longer all or nothing.

3. easingFunction: (Function) Use standard or custom easing functions.

4. easing: (String, "Bounce.easeIn" ) Standard easing functions can be declared as a string, which elevates the need to import easing classes which helps in testing out a few different easing functions, trying to find that perfect ease.

5. loop: (Boolean) An animations can loop infinitely or just a few times.

6. visibility: (Boolean, false) Sets an object's visible property to false after a tween.

7. startVisible: (Boolean, false) Override the default behavior of automatically setting an object's visible property to true on the first frame of the tween.

8. remove: (Boolean) Automatically remove a display object or element after the tween is completed.

9. uid: (int ) A unique identifier, used for pause tweens, so they can be overwritten.

10. onStart, onFrame, onComplete: (Function) Callback functions, returns a reference to the animated object.

11. smartRotation: (Boolean) Forces the tween to rotate in the direction of the closest angle.

12. removeDupes: (Boolean, true) Default behavior is to remove all duplicates, but to save performance, you may want to turn this feature off and manage it on a per tween basis.

One Tween at a time:
Not to be stuck in an endless loop here, but this has a huge impact of how MoveThis is used, so one last time; I promise. Once a tween is completed in the MoveThis engine, it is removed and nulled out. If you need to reverse a tween or replay a previous tween, the best procedure is to start a new tween. MoveThis only allows one tween per property per object to occur at a time. If a tween is started on the x property of a displayObject named foo over 30 frames, when another tween is started just a few frames later for the same object's x property, the first tween will be replaced by the new tween. Once the new tween is finished, it will be removed forever, unless a loop count was added.

One Tween for each property:
When a tween is started, an object (MoveThisObject) is created for each property to be animated. Each tween object is then animated separately. This allows you to start one tween with multiple properties, then update the animation by starting a new tween with of single property value.

Example:

//initial tween
MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30);

//something in our app changes, that require foo to fade out.
MoveThis.startTween(foo,{alpha:0},30);

The x and y properties will continue to tween while the alpha property tween for foo will be replaced and the new fade out tween will began.

The repercussions are that if you have onComplete, onStart, onFrame callbacks assigned to that tween, the callbacks will be called for each property. In the following example, the function "completeHandler" will be called twice, once on complete of the x tween and once on the complete of the y tween.

Example:

MoveThis.startTween(foo,{x:500,y:400,:alpha:1},30,{onComplete:completeHandler);

Three Ways to Make Things Happen Later:
1. delay: The simplest way to delay a tween.

//wait 20 frames before starting
MoveThis.startTween(foo,{x:500},30,{delay:20});

Note: If this is used and another tween is added for the x property of foo, it will be replaced, even if the delay has not expired

2. queueTween: When you know you want to move something later, but do not want it to overwrite a current tween.

//queue this tween for 30 frames
MoveThis.queueTween(30,foo,{x:500});

Note: Once the queue time is complete, the queued tween will replace any existing tweens for the same property of the same object.

3. The pause tween: Used when you want to call a function after a certain number of frames. Easier and requires less processor than using the Timer class.

//call pauseHandler after 90 frames.
MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler});

Note: Frame count is ignored. The pause tween must include an onComplete function.

Note: Replace null with a displayObject reference to have that reference sent to the onComplete function.

Unique ID: By default all pause tweens are persistent, meaning duplicates for the pause property are allowed to exist. If you need to overwrite a pause tween, then give the tween a unique id, when a new pause tween is created with the same id, it will overwrite the previous one.

MoveThis.startTween(null,{pause:90},0,{onComplete:completeHandler,uid:1});

[ad#content_banner]

onComplete Function Example:

function completeHandler(obj:Object):void{
//all target references are returned as objects.
//this allows you to start a new animation or modify the target when the animation is completed
if(obj != null)
obj.visible = false;
}

Easing:
Easing works very similar to all the existing tween/animation engines and works with any standardized easing functions. There are three ways to add eases to your animation.

1. easingFunction: This is the most typical ways of adding ease to a tween. Add a reference to any standardized easing function and you are done.

//add Sine.easeOut as the easingFunction. (the Sine.EaseOut class must be imported first)
MoveThis.startTween(foo,{x:500},30,{easingFunction:Sine.easeOut});

2. easing: An alternate method of #1 and for lazy people like me or someone that wants to try out a few different easing functions without importing them all. Enter one of the included standard tween function names as a string and MoveThis imports the correct easing function for you.

//add Sine.easeOut as the easingFunction without importing the class
MoveThis.startTween(foo,{x:500},30,{easing:"Sine.easeOut"});

3. easingStrength: Not every easing function has to be 100% all or nothing. Adding a 0 - 1 value will allow you to have a little less ease if needed.

//add Quart.easeOut as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{easing:"Quart.easeOut",easingStrength:0.6});

4. ease: Works just like the Flash IDE, set ease from -1 to 1 to automatically add Sine.easeOut or Sine.easeIn, depending on the value.

//add Sine.easeIn as the easingFunction with only 60% ease.
MoveThis.startTween(foo,{x:500},30,{ease:-0.6});

Note: There are two easing classes included to enable looping animations that reverse before looping again. (Arch.linear, Arch.easeIn, Arch.easeOut, Reverse.linear, Reverse.easeIn, Reverse.easeOut, Reverse.easeInOut, Reverse.easeOutIn)

Easing Demo:


[kml_flashembed fversion="10.0.0" movie="http://www.taterboy.com/blog/flash/TweenSamples.swf" targetclass="flashmovie" publishmethod="static" width="500" height="400"]

Get Adobe Flash player

[/kml_flashembed]

Visibility and Remove:
By default all tweened objects are made visible on frame one of a tween. You can override this functionality by adding startVisible:false to the extras.

//the object will not automatically turn visible on frame 1 of the tween
MoveThis.startTween(foo,{x:500},30,{startVisible:false});

MoveThis will also set the visible property to false after a tween is complete or remove that object from the display list. These two features are extremely effective ways to free up memory.

//the object's visible property will be set to false at the end of the tween.
MoveThis.startTween(foo,{x:500},30,{visible:false});

//the object will be removed from the display list on complete of the tween
MoveThis.startTween(foo,{x:500},30,{remove:true});

Pause and Stop:
Pause and Stop only work on tweens that currently exist in the MoveThis engine. You can make a call to MoveThis to pause or stop a particular tween or you can and stop all the existing tweens for a particular object.

//finds a tween for the object "foo" and the property "x"
MoveThis.stopTween(foo,"x");

//finds all tweens for the object "foo" and stops them
MoveThis.stopAllTweens(foo");

//pauses an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",true);

//resumes an existing tween for the x property of the object "foo"
MoveThis.pauseTween(foo,"x",false);

You can also pause MoveThis using MoveThis.pause(true);

Plugins:
Plugins are a great way to add functionality and new tween-able properties to objects. Included are a couple classes to animate the color or brightness of an object. Plugins can be installed at runtime.

var plugin:Object = {brightness: com.hdi.animate.Brightness};
MoveThis.install(plugin);

The installedPlugins property of MoveThis is an array of all the currently installed plugins.

var plugins:Array =  MoveThis.installedPlugins; // [returns an array or objects]

Working with Flex 4 SDK:
To use MoveThis with Flex 4's Group and Element classes, uncomment 3 snippets of code from com.hdi.animation.MoveThisEngine, to enable remove functionality. (sample snippet)

/***************************************************************
* FLEX 4 SDK: UNCOMMENT FOR Group and Element support (2 of 3)
***************************************************************/
/*
try{
moveObj.targetObj.parent.removeElement(moveObj.targetObj as IVisualElement);
}
catch(e:Error){}
*/
/*** END FLEX 4 SDK ********************************************/

UPDATE 1.20, 4/21/11 :

Updated code to run a little faster, using while loops instead of for each loops.
Added Sound or Mixer volume plugin to fade volume in and out.
Added methods for stopping queued animations

Download Complete Source Files

What tween engines do you like to use and why?

AS3 Super Loader Part 2
This post is a continuation of the Action Script 3 Super Loader, find though this tip could have many adaptations besides the example below.

Many may already know that when you go to the Publish Settings/ HTML window, there is a drop-down that allows for the choice of HTML templates to use with your .swf. When Flash publishes the HTML page along with the .swf, it dynamically creates the new HTML file that will host your Flash movie, with the correct width, height, file name, background color of the .swf in the source code. Many developers use this HTML page to copy the embed code into another file. Some people ignore this feature all together and use Dreamweaver to produce the code or have a custom HTML template that they modify manually.

There are other options in this drop-down that include things like Flash version checking, scorm support, and SSL encryption. But the reality is, most of us would not use these files in a website or to show a client without at least a little modification. That is why we all probably have a few HTML templates of our own laying around.

Why not take those templates and make Flash HTML Templates, which is super easy. My default template has some custom css styles, javascript functions and centers the .swf on the page. I can use this HTML file to show development progress to a client.

I also have some custom scorm templates that work with a few different tracking systems. A lot of us use swfObject, you can even build a template that produces the correct code for swfObject on export. This may not be a huge time savings, but it is part of a smoother workflow.

This hint is about hooking up our Super Loader to an HTML template, but it should be enough information to build any kind of template.

First off, you should backup your existing HTML template files in case of any errors and more importantly, back up your custom templates in case a Flash update replaces them or a system crash. Plus you may want to share you templates or use them to standardize the workflow of your development team.

The templates are located in User Folder/Library/Application Support/Adobe/Flash CS3/en/Configuration/HTML/ on the mac, or C:Program FilesAdobeAdobe Flash CS3enConfiguration on the PC.

Inside the default.html file, you will see the script for embedding the .swf using AC_RunActiveContent. This script shows the best description of what most of the variables are.

Other Variables that are not well defined below:
$TT = the name that will show up in the drop down menu.
$DX, $DS, and $DF = flash version detection and the AC_RunActiveContent generation.
$CS = metedata tag
$PO = param tags for width, height, quality and color.
The rest is just HTML, so go crazy.

Modifying the Super Loader Stage class:
The first thing we need to do is modify the Super Stage class to allow for a dynamic source file, with a variable check.

class original source here.

[ad#content_banner]

package com.HDI.stage {
/*import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.MouseEvent;
import flash.geom.Rectangle;*/
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;

public class SuperStage extends MovieClip {
//External Variables:
var fps:Number = 30;
/* remove the variable definition from swfURL*/
var swfURL:String;
var ldrURL:String = "loaderbar.swf";

//Loader Variables:
var loadComplete:Boolean = false;
var loadPerc:Number;
var loaderCnt:Number = 0;

//Internal Objects:
var mainMovie:Object;
var mainLdr:Object;
var mainContainer:MovieClip;
var loaderMC:MovieClip;

public function SuperStage():void{
init();
}
private function init():void{
/* Add variable check here and use a default swf name if swfURL does not exist.*/
if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}
//Set all the stage properties onload
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//load the main container and the loader container
/*
this is not manditory and can make things more complex,
but so that the loader always stays on top, I add these to MovieClips
then load everything else inside these clips.
Load the loaderMC second so that it remains on top.
*/
mainContainer = new MovieClip();
addChild(mainContainer);
loaderMC = new MovieClip();
addChild(loaderMC);

//setup stage init incase I need it later.
loaderInfo.addEventListener(Event.INIT,initStage);

//start to load the loader bar.
loadObject(loaderMC,ldrURL,null);
stop();
}
function initStage(ev:Event):void{
//stage.stageWidth = thisWidth;
//stage.stageHeight = thisHeight;
}
//main loader method
function loadObject(targ:Object,path:String,mon:Object):void{
var ldr:Loader = new Loader();
var ldrReq:URLRequest = new URLRequest(path);
ldr.load(ldrReq);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldrFin);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ldrProgress);
ldr.name = "ldr" + loaderCnt;
targ.addChild(ldr);
loaderCnt ++;
}
//finish loading. first two items loaded will be ldr0(loader bar) and ldr1(main content)
function ldrFin(ev:Event):void{
if(ev.target.loader.name == "ldr0"){
mainLdr = ev.target.content;
mainLdr.loadStat = true;
mainLdr.x = (stage.stageWidth/2)-(mainLdr.width/2);
mainLdr.y = (stage.stageHeight/2)-(mainLdr.height/2);
loadObject(mainContainer,swfURL,mainLdr);
}
else if(ev.target.loader.name == "ldr1"){
mainMovie = ev.target.content;
stage.frameRate = ev.target.frameRate;
}
}
//progress handler, sends loading info to loader bar.
function ldrProgress(ev:ProgressEvent):void{
if(mainLdr){
mainLdr.ldrMon(ev.bytesLoaded/ev.bytesTotal);
}
}
}
}

The rest happens in the HTML Template:
The new template is a modified copy of the default template.
It will set the stage swf as the source, then we will use flashVars to load in the current project name that will be used by the loader to display our current file.

$TTSuper Loader
$DXDefaultDetection.html
$DS
Display Adobe Flash Movies in HTML files updated for Active Content. NOTE: Publishing this template also creates AC_RunActiveContent.js in your HTML output folder which must be uploaded with the HTML.
$DF



$CS
$TI






$MU

$MT


©2008 taterboy, Inc. All Rights Reserved

Pretty Simple.
source

UPDATE

Updated the following code in "com/HDI/stage/SuperStage.as" so that the Loader will actually work with FlashVars. Also updated "FlashVars" in the HTML template code to have a capital "F". The source files have been updated as well.

if(loaderInfo.parameters.swfURL){
swfURL = loaderInfo.parameters.swfURL;
}
else{
swfURL = "sample.swf";
}

Here is an official geek badge for any Flash content. Not only does it display the loading percentage in binary, online it also has a dual knight Rider type pulsing effect. It was built a few years ago with high hopes of using it on something cool. I hope someone can find a cool home for it.

I am sure if I did not get the binary display just right someone will let me know, what is ed just be nice.

To use it, place it on the first frame of your flash file you need a loader for. also on that frame place a stop action and a function called imLoaded();

Here is an example.

// first frame, same as the loader component.
function imLoaded(){
gotoAndPlay(2);
}
stop();

[kml_flashembed movie="http://www.taterboy.com/blog/flash/BinaryLoader.swf" height="50" width="100" fversion="9" /]
Here is the FLA
With the nature of vectors being smaller than bitmap images in file size, more about I typically try to illustrate everything I do for Flash in Illustrator first. I love Illustrator as an illustration tool. Although Flash has made some great progress it's illustration tool set, discount it just does not come close to the power and features of Illustrator. I also find Illustrator really fast for laying out design projects and more illustrative graphics then modeling and detailing in photoshop. Like any relationship, viagra 60mg my affection for illustrator is not without frustration and we have to learn to accept some of the faults, if you can pardon my Dr. Phil type metaphor, to make it work. So here are some workarounds for some illustrator issues and a couple tips to help you work better with this great tool.


1. New Document Profiles:
Tired of deleting all the colors, brushes and symbols every time you create a new Illustrator document? Sick of making a new template because you accidentally saved over that last one? Illustrator uses Template files for each document profile. Those template files are standard .ai files so you can edit the source of each profile with ease. By deleting all those colors, brushes, and symbols out of these template files, all the new documents you create will only contain the elements and setting you want. You can even create new profiles.
On a Mac they are located in the Library/Application Support/Adobe/Adobe Illustrator CS3/New Document Profiles folder.
On the PC look in Documents and Settings /*User Name*/Application Data/Adobe/Adobe Illustrator CS3 Settings/New Document Profiles/


default swatches
default brushes
default symbols

If you add a new file, it will show up in the profile drop down of the new file dialog box.

[ad#content_banner]

2. Free Transform Tool (works the same way in Photoshop and Flash):
This is one of the most powerful tools in the tools palette. If you can imagine the Oxy Clean guy going on about this tool, that's how great it is.
The real power comes in the form of augmenting it's functionality with keyboard keys. After selecting a node of the free transform tool bounding box, add the following keys to change its behavior. ***The key is to select a node first, then adding the extra keys. These special keys are:
Shift: Constrains scaling to the original aspect ratio, rotation to 45 degrees, free distort to limited angles, and skew to current height or width.
Command (Ctrl PC): Free distort of corner or side. Works well for mapping and tweaking flat artwork onto a plane in perspective.
Command + Option (Ctrl + Alt PC): Skewing
Command + Option + Shift (Ctrl + Alt + Shift PC): Shear, takes an object and lays it back in perspective.

Free Transform

3. Nudging artwork with the arrow keys:
On some older machines this seems to be more of an issue. When you nudge selected items around the art board, sometimes you do not see the results for a second or two. Normally, it happens with large complex artwork. I find that if I tap Shift, Command (Ctrl), or Space bar, the screen refreshes and I can see the results a lot faster. Holding the Shift key while you nudge is like a 10x nudge. To clarify, 10 normal arrow only nudges equal 1 shift + arrow nudge.

4. PathFinder divide and unite:
There are two buttons in the Pathfinder Palette that I use the most, Divide and Unite. From the old days of spot color separations, I have been trained to keep my artwork as clean as possible. This is also important if you want to animate vector artwork and make sure it does not blow up when you bring it over to Flash. Uniting shapes that have the same color helps to keep your artwork organized and clean.
Pathfinder is a huge timesaver while illustrating. The less lines you have to put down saves time. Especially if those extra lines are tracing existing lines. I will give an illustration tutorial and go over this technique in greater detail. But here is a simple tip for now. If you have a single shape that you want to fill with two different colors, do not draw another shape, copy the original and divide it.
In the example below:

Unite and Divide

A. shows a shape, with it selected, copy & paste in front. Draw a path, select the top copy and the new path & divide. Delete the top half.
B. shows the original shape with a 6 point stroke. Select the original shape, copy & paste behind. Add the 6 point stroke, expand and unite. *for best results, change the gradient to a solid color before expanding.
C. Shows the final button. The benefits of this technique are: 1. I can modify the the bottom shadow shape, like adding an arch or wave without having to match it with a top shape. 2. We preserve the original shape for easier editing later. 3. very clean artwork.

5. Align & Average:
If you ever spend more then a second wondering if something is centered, you are wasting time. Open that align palette and force those objects to be centered, justified or spaced out evenly. Nothing looks worse then artwork that is so close to being aligned, but just a tad off. Align only works on items that are ungrouped or multiple groups.
Average is like align, but only works on path nodes. Sometimes while illustrating a line, it takes a second or two to get a line perfectly straight. Just select the two nodes and use the Average dialog ( Command + Option + J mac) (Ctrl + Alt + J PC) and choose horizontal or vertical. and they will straighten right up.


Align palette
Average Dialog

6. Selection preferences. Arrows and Type:
By default the preference (Selection & Anchor Display) for "Object Selection By Path Only" is not checked, meaning you can select an object by clicking anywhere on the object face. You can select items underneath by toggling preview to wireframe (Command + Y or Ctrl + Y). By enabling this feature, you will be able to select shapes without toggling Preview, hiding or locking other objects, which will make you more efficient. It may take some getting used to if you have been using the default setting all along. Likewise, there is a preference for "Type Object Selection By Path Only", which is disabled by default. Enabling it will allow you to select paths behind or around text.

Selection Prefs

7. Colors and swatches:
I would like to do a whole post on color swatches and illustration soon, but until then, color swatches can be your friend. I do not mean the ones that are in the swatches palette when you open a new document. If you read the earlier tip, we should be rid of them by now. Making a custom color palette based on mood, branding or whatever you want to communicate is scores better than making up colors on the fly or picking colors because they just happen to be in the color palette. Most computers can display 16 million colors telling us there are a many more Hughes of green then the lime and forest green in the default color palette. Saving colors to swatches saves us from trying to make the same color over and over. Saving colors as spot color is cool for certain printing jobs and if you ever want to update a color, you can do it one time and every object filled or stoked with that color will be updated as well. The down side is spot colors make horrible gradients. I normally stick with RGB swatches and use Select Same Fill or Stroke Color to update colors if that arrises. Also, if you have an illustrator file with a a bunch of swatches and you need them in a new illustrator document. You can use Window/Swatch Libraries/Other library and a new swatch pallet will appear with the needed swatches from the Previous Illustrator file.


New Colors

8. Actions (same in Photoshop):
Actions are the coolest thing since Command + Z (Ctrl + Z PC). There are certain combinations of tasks that I perform at least 50 times or more in a single illustration. I make actions of those combos and assign an F key to it. This saves tons of time. My most use actions are probably Expand + Unite, which merges the stoke and fill into one shape. The other is Place just because there is not a default keyboard shortcut for that menu item. I also use actions for special transforms that I will have to do more then once or we can build template files with actions so that anyone with illustrator or Photoshop can recreate the transforms to match the original. ** The most important thing to know about actions is saving them. I keep apps open for weeks at a time. Any crash during that time will erase any actions you have created.

9. Just say no to strokes:
One of the most time consuming things about Flash development is fixing artwork imported from illustrator. With CS3 that chore has been greatly reduced, but there are still a few things that still do not translate the same. Strokes are a large contributer to some vector artwork in flash looking terrible. If you try to Convert Stokes to Fills in Flash, many times most of the stroke will just disappear. It is best to do all that in Illustrator using the previous tip, as well as some good planning to keep your artwork clean. There are some good reasons to use strokes in Flash, otherwise getting rid of them in Illustrator will make life much easier and your graphics looking better.

Cleanup Strokes

10. Grouping:
One of the reasons Illustrator is so much more efficient then photoshop for comping up rough layouts is that you do not need to know what layer the artwork is on to move or transform it. You just select the artwork directly and transform away. Using groups wisely will diminish the amount of time it takes to make selections. Once an section of an illustration is complete, you should make it into a group. The next time you need to transform that group, it is only one click away. Using the Command + Option + Tab (Ctrl + Alt + Tab PC) to toggle the open and closed arrow selections tools will make the different types of selections happen a lot quicker. Also Command + Option + Double-Click (Ctrl + Alt + Double-Click PC) with the open arrow selection tool will select a sub-ground within a group. Another click will add the whole group to the selection.

...and The Most Important:
Learn as many keyboard shortcuts you can. This is not an illustrator only tip. As with any app that you work in and expect to be proficient at, information pills you should learn the key-board short cuts. In the manuals that come with the box, there is normally shortcut charts. If you did the download, you can find them online. Most Adobe apps have the ability to re-assign key-board short cuts as well. I would suggest against it, unless it is necessary, because if you ever go to work at a different location, or have to show someone something on a different computer, it helps if the shortcuts are the same. Some reasons we have had to change shortcuts in the past are, In Illustrator CS2 and previous, The shortcut for switching between the hollow and solid arrow selection tools, was Command + Tab (Ctrl + Tab on PC). On a mac, all the way back to OS 8, would instead toggle the application switcher. So instead of getting the hollow arrow selection tool, you would get a web browser or other open app instead.

In Photoshop CS2 and before, Command + Option + D (Ctrl + Alt + D on PC)was the short - cut for Feather Selection. On a Mac since the introduction on the dock, that shortcut was used to toggle the dock to appear and disappear. Both of these shortcuts were easily fixed by customizing the shortcuts to require and extra Key. That way Command + Option + Tab to toggle the selection Arrows in Illustrator and Command + Option + Shift + D to get the Feather section dialog box.

I believe Illustrator CS3 now comes pre-modified? (I seriously can not remember if I had to change that or not and I can not find any documentation on the Toggle Selection Arrow short cut as it this post). But Photoshop CS3 has done away with the Feather Selection dialog box and replaced it with Refine Edge which is Command + Option + R (Ctrl + Alt + R on PC).

Here is a resource for keyboard shortcuts. They are not complete, but in a easier format to print.
http://www.keyxl.com/
Also for Photoshop Only Shortcuts :
http://www.photoshopsupport.com/tutorials/jennifer/keyboard-shortcuts.html

Flash:
http://www.adobe.com/go/tn_12105

Official Adobe help docs:
http://livedocs.adobe.com/en_US/Illustrator/13.0/WS714a382cdf7d304e7e07d0100196cbc5f-642a.html

http://livedocs.adobe.com/en_US/Photoshop/10.0/WSfd1234e1c4b69f30ea53e41001031ab64-76b9.html

http://livedocs.adobe.com/flash/9.0/UsingFlash/WS4B6E7EC1-81C9-4d9d-96C0-9C01EB96E1FA.html
There is a huge buzz around the new iPhone SDK, nurse more about at least in some circles. Here is a collection of a few iPhone interface objects, ask in vector (Illustrator CS3), seek for anyone wanting to design an interface for the iPhone or an iPhone look-a-like app.


Iphone Artwork 2

Iphone Artwork 1

[ad#content_banner]

Iphone Artwork 3

Iphone Artwork 4


source.

There is a huge buzz around the new iPhone SDK, nurse more about at least in some circles. Here is a collection of a few iPhone interface objects, ask in vector (Illustrator CS3), seek for anyone wanting to design an interface for the iPhone or an iPhone look-a-like app.


Iphone Artwork 2

Iphone Artwork 1

[ad#content_banner]

Iphone Artwork 3

Iphone Artwork 4


source.

Random is a funny thing. You are working on a site or a game and think, pharmacy "let's make this part random to add some interest. You add your new code and realize that now things are repeating where they were not before Or the game experience is now really inconsistent.

That is because random is well, random. It is not 1, 2, 3, 4 any more, but it is also not a consistent distribution or values ether. The first sample is a concept built to prove a point I felt very strongly about, that I wagered lunch on it. I lost, but it is still an interesting exercise.

Each graph produces random numbers from values 10, 100, and 1000 then counts how many times the random number is within 10%, 20%, 30% etc., of those values. The number in the Calculate button tells how many times the random numbers are produced for each value.

If you press the Calculate 10 button, the first column will show how many times the random numbers are produced from the value of 10, The second column uses the value of 100 and the third column shows the percentage of random numbers from the value of 1000.

The purpose of the test was to see if making random numbers from larger values resulted in a more even distribution of random numbers. Increasing the amount of each loop does help, so try out the Calculate 100, 500, 1000 and 2000 buttons as well. The Calculate 2000 button loops 6000 times and may cause Flash to hang if you are not running a good CPU, so press that one at your own risk.

[kml_flashembed movie="http://www.taterboy.com/blog/flash/randomTest.swf" height="568" width="496" fversion="9" /]

[ad#content_banner]

The Second example shows how to use random to shuffle items so that they do not repeat. I wish iTunes would use this type of system for their shuffle control****.

Click the "Shuffle" button to rearrange the numbers and click "123 Order" to place them back in order.

The process is simple, build an array that will hold you list of Numbers, Names, or Object References. Then add a key to each section of the array, this will hold your random numbers. When the array is sorted to the key, all the items will be shuffled with no repeats.

function setOutput(val:int):void{
shuffleArr = new Array();
for(var i:uint = 1; i<= boxCnt; i++){
var randKey:int = Math.random()*boxCnt;
//trace(randKey);
// Where id is is, place your data/object you want sorted.
if(val == 0){
shuffleArr[i-1] = {id:i,key:i};
}
else{
shuffleArr[i-1] = {id:i,key:randKey};
}
shuffleArr.sortOn("key",Array.NUMERIC);
var tCnt:int = 1;
for(var t:String in shuffleArr){
this[boxName + tCnt].op.text = shuffleArr[tCnt-1].id;
tCnt ++;
}
}
opt.text = "Status : Complete";
}

[kml_flashembed movie="http://www.taterboy.com/blog/flash/randomShuffle.swf" height="300" width="550" fversion="9" /]

Sample 1 is AS2 and sample 2 is AS3, source for both below.
Here is the Source

****iTunes Shuffle Feature / Bonus Tip:
I work around for iTunes shuffle feature that randomly picks songs instead of using a true shuffle mechanism is to build two dynamic Playlists. The first one is a list of songs in the desired genres (Genre , is, someGenre). The second playlist if the one you will use to listen to which will include the songs from the first playlist (Playlist, is, firstPlayList). Then set the limit to [1000] [items] selected by [least recently played] .

Now your songs will cycle out of this playlist as they are played, you can also use shuffle control on this list.
There is a huge buzz around the new iPhone SDK, nurse more about at least in some circles. Here is a collection of a few iPhone interface objects, ask in vector (Illustrator CS3), seek for anyone wanting to design an interface for the iPhone or an iPhone look-a-like app.


Iphone Artwork 2

Iphone Artwork 1

[ad#content_banner]

Iphone Artwork 3

Iphone Artwork 4


source.

Random is a funny thing. You are working on a site or a game and think, pharmacy "let's make this part random to add some interest. You add your new code and realize that now things are repeating where they were not before Or the game experience is now really inconsistent.

That is because random is well, random. It is not 1, 2, 3, 4 any more, but it is also not a consistent distribution or values ether. The first sample is a concept built to prove a point I felt very strongly about, that I wagered lunch on it. I lost, but it is still an interesting exercise.

Each graph produces random numbers from values 10, 100, and 1000 then counts how many times the random number is within 10%, 20%, 30% etc., of those values. The number in the Calculate button tells how many times the random numbers are produced for each value.

If you press the Calculate 10 button, the first column will show how many times the random numbers are produced from the value of 10, The second column uses the value of 100 and the third column shows the percentage of random numbers from the value of 1000.

The purpose of the test was to see if making random numbers from larger values resulted in a more even distribution of random numbers. Increasing the amount of each loop does help, so try out the Calculate 100, 500, 1000 and 2000 buttons as well. The Calculate 2000 button loops 6000 times and may cause Flash to hang if you are not running a good CPU, so press that one at your own risk.

[kml_flashembed movie="http://www.taterboy.com/blog/flash/randomTest.swf" height="568" width="496" fversion="9" /]

[ad#content_banner]

The Second example shows how to use random to shuffle items so that they do not repeat. I wish iTunes would use this type of system for their shuffle control****.

Click the "Shuffle" button to rearrange the numbers and click "123 Order" to place them back in order.

The process is simple, build an array that will hold you list of Numbers, Names, or Object References. Then add a key to each section of the array, this will hold your random numbers. When the array is sorted to the key, all the items will be shuffled with no repeats.

function setOutput(val:int):void{
shuffleArr = new Array();
for(var i:uint = 1; i<= boxCnt; i++){
var randKey:int = Math.random()*boxCnt;
//trace(randKey);
// Where id is is, place your data/object you want sorted.
if(val == 0){
shuffleArr[i-1] = {id:i,key:i};
}
else{
shuffleArr[i-1] = {id:i,key:randKey};
}
shuffleArr.sortOn("key",Array.NUMERIC);
var tCnt:int = 1;
for(var t:String in shuffleArr){
this[boxName + tCnt].op.text = shuffleArr[tCnt-1].id;
tCnt ++;
}
}
opt.text = "Status : Complete";
}

[kml_flashembed movie="http://www.taterboy.com/blog/flash/randomShuffle.swf" height="300" width="550" fversion="9" /]

Sample 1 is AS2 and sample 2 is AS3, source for both below.
Here is the Source

****iTunes Shuffle Feature / Bonus Tip:
I work around for iTunes shuffle feature that randomly picks songs instead of using a true shuffle mechanism is to build two dynamic Playlists. The first one is a list of songs in the desired genres (Genre , is, someGenre). The second playlist if the one you will use to listen to which will include the songs from the first playlist (Playlist, is, firstPlayList). Then set the limit to [1000] [items] selected by [least recently played] .

Now your songs will cycle out of this playlist as they are played, you can also use shuffle control on this list.
This is the first in a series of posts about some issues with Flash, page ActionScript 3 and current work-arounds.

1. Timeline Animation and Scripting:
I could not believe this issue when I ran across it for the first time. I really hope it is a bug. If you have code on the first frame of a timeline, patient then advance the timeline, click the objects on the next frame are not available to your code until the frame after.

This simple code does not work: (place code on frame 1 and place mc_clip on frame 2)
gotoAndStop(2);
mc_Clip.visible = false;

You get an error that says mc_Clip equals null if it did not exist on the first frame.

The rendering sequence has the script run before the items are added to the display list, so they do not actually exist on that frame until the next render sequence runs. With all of ActionScript 3's benefits, I can not believe this oversight. After all Flash is a timeline based app right? Even Flex has a frame-rate.

I guess the correct Open Object Oriented approach is to have everything on each frame wrapped into a class? That way it could handle itself and all its children on initiation. But, it is still a time-line based app! To tell an object to do something on a particular frame used to only take 1 line of code, now, not so much.

The best work-around I could come up with after hours of experimenting is to do a frame loop to wait two frames. One interesting approach was to make a list of objects you need to interact with, then use the ADDED event to check for each item. Once they all come back as true, then proceed. This approach was not a consistent as the frame loop method. I built a not so simple class that handles the advance frame, waits until the objects on that fame are available to scripting, then calls a predefined method.

package com.hdi.utils{
import flash.display.MovieClip;
import flash.events.Event;

public class FrameAdvance extends MovieClip{
private var target:Object;
private var frameNumber:int;
private var frameLabel:String;
private var callType:String; //_play,_stop
private var endFunction:Function;
private var childNum:int;
private var countDown:int;

public function FrameAdvance(targ:Object,frameNum:int,frameLab:String,type:String,endFun:Function):void{
target = targ;
frameNumber = frameNum;
frameLabel = frameLab;
endFunction = endFun;
callType = type;
countDown = 1;
init();
}
private function init():void{
if(frameNumber > 0){
callType == "_stop" ? target.gotoAndStop(frameNumber): target.gotoAndPlay(frameNumber);
}
else{
callType == "_stop" ? target.gotoAndStop(frameLabel): target.gotoAndPlay(frameLabel);
}
childNum = target.numChildren;
this.addEventListener(Event.ENTER_FRAME,childAdded);
}
private function childAdded(ev:Event):void{
if(countDown == 0){
if(this.hasEventListener(Event.ENTER_FRAME)){
this.removeEventListener(Event.ENTER_FRAME,childAdded);
}
endFunction();
}
countDown --;

}
}
}

[ad#content_banner]


[kml_flashembed movie="http://www.taterboy.com/blog/flash/frameAdvance.swf" height="208" width="414" fversion="9" /]

source here
If you would like to contact us with with questions or suggestions on how to improve, visit medicine please use the form below.


Thanks.