Wednesday, October 12, 2011

Objects in Scripting

In scripting, objects are probably one of the most important components if not the most important component because without them we wouldn't need any other code, merely because we would have nothing to animate. To be blunt, objects are anything that has the metaphor of existence in the world. Objects range anywhere from flowers, dogs, planes, people, buildings and any other pictures all over the internet and things you can place on the stage. Buttons created in flash are objects as well because we created them and they now exist. Probably the trickiest object to wrap your head around would be sounds because unlike the others, you can't see sound. However, they still have the metaphor of existence or our world would be a very quiet one.

I mentioned before that the objects are anything on the stage. Well, in Action Script anything you place on the page to work with is an object and that page to work on is known as the stage. Think of it as our world and how it holds all the objects from water to people. Without it first existing in the world or in this case, the stage, you can't animate or control it.

Existing on the stage is how we can get objects to move and do what we want but there is a little more to that than just dropping it on there. In order to animate you need to make it either a button or a movie clip and give it an instance name. However, this explanation is just so you understand what a symbol is. To give you a look at some of the code and what to expect I have written a very basic code for a button.

jump_btn.addEventListener(MouseEvent.CLICK, personjump)
function personjump(event:MouseEvent){
              person_mc.gotoAndPlay("jump");
}

Thats a lot to take in I know and it takes a little bit to understand, but for now just focus on the highlighted sections. Those are the objects in this code and essentially your telling one to make the other jump. In this case it is jump_btn that is causing person_mc to jump. Those are the objects that we have created and are giving actions through some coding. Think you have a good grasp on objects? If you don't right away thats no big deal because it will come to you soon I guarantee it.

No comments:

Post a Comment