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.

No comments:

Post a Comment