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 ‘

‘;
?>

Leave a Reply