PDA

View Full Version : Passing Parameters in Functions and Event Listeners



urieljuliatti
June 21st, 2009, 11:17 PM
I'd like to know what's the different using global functions and functions with param..

Why using params? When the as3 developer uses it?

Sory about this simple question.. I'm new on AS3

Somebody help me..

BoppreH
June 22nd, 2009, 07:37 AM
What do you mean by "global functions"?

And parameters are used when a function have to act on an unknown object. For example, let's say you have a game in which the player has to catch some items. Every time the player catches an item, this item disappears with a cloud of smoke. To be able to make things disappear easily, you make a function like this:


function removeItem(object:DisplayObject):void {
object.visible = false
var smoke:SmokeCloud = new SmokeCloud()
smoke.x = object.x
smoke.y = object.y
smoke.play()
}

removeItem(coin)

This code will make the item "coin" disappear and an instance of the SmokeCloud class play in the place.

.ral:cr
June 22nd, 2009, 09:34 AM
a global function would be "trace" because works from anywhere, you don't need to import it. trace takes also some parmeters.

urieljuliatti
June 22nd, 2009, 07:31 PM
Good! I'll try to understand doing some exercises here