PDA

View Full Version : [AS] dragger.onPress=function()



Ogier Midget
March 4th, 2005, 02:32 PM
Hello,
I am currently working on the Slider Bars tutorial at http://www.kirupa.com/developer/mx/slider.htm . I got dragger to work, I just want to better understand the dragger.onPress=function() part.

With a normal function you have:
function hello(){
trace("hello");
}

Then when I wanted to run the function, I would use:
hello();

Ok so if dragger is pressed (onPress) then it creates a function, right? So how do you run the function? Or is the function running as I'm pressing dragger?

I hope you can understand my question.

Thanks

Smee
March 4th, 2005, 03:04 PM
onPress is an event, by saying onPress = function, you're telling it to run that function when the onPress event is preformed.


When you have a function like your example:

function hello(){
trace("hello");
}

You can think of writing the "hello()" somewhere in your code as an event, and it runs the function "hello" when you preform that event.. I hope I made sense there :-/

Ogier Midget
March 5th, 2005, 04:33 PM
So pretty much its a shortcut? I could easily have done:

function hello(){
trace("hello");
}

onPress(){
hello();
}

But by doing:

onPress=function(){
trace("hello");
}

.. it saves me time, right?

Krilnon
March 5th, 2005, 04:56 PM
It'll only save you time if you just want to use it once. If your function is quite a bit more complex than that, and you want to use it more than once, it's better just to define the function once and run it multiple times. This also will end up saving filesize by a bit.