Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, December 13, 2011

Arguments and Methods in Scripting

Arguments and Methods are two more important concepts in the scripting world. Without these two pieces of code the objects are there, but nothing can happen because nothing is telling it what to do.

Lets refer back to our code that we wrote for the objects.

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

The parts that are highlighted are methods. Methods essentially hold functions that affect the object in some way. For instance, in the first method it is holding MouseEvent.CLICK, which means that nothing will happen to this object until the mouse clicks on the the object which in this case is the jump button. Also, the easiest way to figure what is a method, is by looking directly after it. Methods are always followed by parentheses. They may have stuff in them and they may not, but they always have parentheses.

Now lets look at that code again.


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

The next part that is highlighted is an argument. Arguments reside within the methods and give information to the methods on what needs to happen when the button is clicked. For example, the personjump argument is listed below in the second line as an argument then. It is now holding important information. The information is what actually happens meaning the person is going to jump. The timeline is going to move across to wherever it is marked "jump." Essentially this particular method links the two parts of top and bottom. The button will not cause the person to jump unless personjump is telling the person to jump on the timeline.

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.