PDA

View Full Version : differences with function calling (event = function() vs event = myFunction(x,y))


rfan622
08-13-2004, 02:33 PM
I have an event that is to be triggered a MC's OnPress and OnMouseMove. However when I make the event a function, the OnMouseMove is not continuous rather it only runs it at the end of the move. While when I insert the code in the function ala AS 1.0, the runs the function continously (what I desire the function to do).

Here's some code to better illustrate my point. This is ran from within the MC.
Example 1

this.OnPress = function () {
mouseListener.onMouseMove = function() {
//manipulate x,y of movieclips
}
}


VS.

Example 2

this.OnPress = function () {
function manipMC(x,y) {
//code to manipulate
}

mouseListener.onMouseMove = manipMC(g_x,g_y);
}


Example 1 works as I want it to. The manipulation occurs while the mouse is moving and the clip is pressed. However in example 2, the manipulation only occurs when the clip is released.

Trevor Harrison
08-13-2004, 04:23 PM
in your example 2:
mouseListener.onMouseMove = manipMC(g_x,g_y);

you are assigning the result of the call to manipMC() to the onMouseMove function pointer. Not good. You probably want:

mouseListener.onMouseMove = manipMC;

senocular
08-13-2004, 04:28 PM
of course, inbuilt events of the such cannot be passed arguments like that. You'll have to reference those values some other way from within the function

rfan622
08-13-2004, 04:57 PM
ahhh..got it. so what does it exactly mean when you reference a method with parenthesis vs w/o parenthesis?

Trevor Harrison
08-13-2004, 06:15 PM
ahhh..got it. so what does it exactly mean when you reference a method with parenthesis vs w/o parenthesis?

With parens means call the func/method.

Without parens means you are talking about the function itself. Indeed, in AS, a function is an object. You can get and set properties and such of a function... ie.

function foo()
{
trace("blah");
}

foo.xyz = 1; // set an attribute of xyz in the func object.

or, more usefully, you can indirectly call a function, forcing its 'this' param:

foo.call(mc, arg1, arg2);

See Colin Moock's book for good details.

-Trevor

senocular
08-13-2004, 06:21 PM
welcome back Trevor ;) glad to see you around again :)

Trevor Harrison
08-13-2004, 06:33 PM
heh. I'm not in Mt. Airy anymore though..... moved down the road a few miles to New Market.

One of these days I'm going to have to take you out to lunch and pick your brain, or at least get enough brownie points so that I can pester you personally when I run into something.

-Trevor

senocular
08-13-2004, 08:30 PM
hey, you're a-ok in my book, neighbor. Feel free to pester me whenever you need to right now. :D