Short answer: for a case like this, use the sendSprite command instead, e.g.,

sendSprite(1, #bumpCounterH, xref, 2)

SendSprite will send the message to all instances of all behaviors attached to the sprite. Assuming that there are no other behaviors attached that have a bumpCounterH routine, this should work fine.

As you figured out, the "call" approach will work correctly if you have the proper object reference to the proper script instance. An ideal way to use "call" is when objects (and/or behaviors) have a way of "registering" themselves to the thing that will wind up calling them back.

Lets say that two different behaviors want to be called back when someone clicks on yet a third behavior. Each of the two behaviors could send a mRegister message passing "me". me will always refer to the current instance of the current script. On the receiving side, the script with the mRegister, simply adds the parameter to a list of objects/behaviors that want to be called back:

property pListOfBehaviorsThatWantToBeCalledWhenIAmClickedOn

on beginSprite me

on new me
  pListOfBehaviorsThatWantToBeCalledWhenIAmClickedOn = []  -- start off empty
end

-- Build up a list of objects/behaviors that want to be called back
on mRegister me, instanceThatWantsNotification
append(pListOfBehaviorsThatWantToBeCalledWhenIAmClickedOn, instanceThatWnatsNotification)
end


-- Our action has happened, lets call back everyone who registered
on mouseDown me
call(#someCallbackRoutine, pListOfBehaviorsThatWantToBeCalledWhenIAmClickedOn, etc.)
end


I hope that makes sense.

Call will be faster because it targets only the instances you really want. But as you found out, it is much more difficult to get to those references. Bottom line, use sendSprite and it should work just fine.


Also. "getAt" is a very old form. Newer Lingo allows you to get at elements of a list through bracket syntax:


getAt(myList, itemNumberX)

is the same as the newer and cleaner:

myList[itemNumberX]

So, there is no need to use getAt any more.

Irv

At 11:00 PM +0200 2/16/04, Peter Bochan wrote:
Hello everyone,

I've got a sprite with 2 behaviors attached to it: 1 - "horizontal movement"
(it has the bumpCounterH handler with three args), 2 - "vertical movement"
(it has the bumCounterV handler with three args too). I use the call command
to send a message to the first handler along with some parameters. What the
Director MX documentation says is (p.370):

on mouseDown(me)
  xref = getAt(sprite(1).scriptInstanceList, 1)
  call(#bumpCounterH, xref, 2)
end

This works fine, it calls the specified handler and passes the defined
argument. But should the call command be used only with getAt list command?
What if I want to reference the behavior via its name?

e.g.

on mouseDown(me)
  call(#bumpCounterH, sprite(1).scriptInstanceList, "horizontal movement",
2)
end

Or what if I want to use this command directly?

e.g.

on mouseDown(me)
  call(#bumpCounterH, sprite(1).scriptInstanceList, 1, 2)
end

I tried this, it "works". I mean the right behavior is being called but the
name of the behavior comes as the first parameter, and the first parameter
in the call shows up as a second parameter in the handler being called and
so on. So this kind of shift is going on.

So does scriptInstanceList work only with getAt command or with set
variables?

--------------

At this link(http://www.peb965.cv.ua/list_questions/scriptInstanceList.htm),
you may paste the following to the message window:
call(#bumpCounterH, sprite(1).scriptInstanceList, 1, 560,899,210)
-- you shall see the shift of arguments

call(#bumpCounterH, sprite(1).scriptInstanceList, "horizontal movement",
456,220,325)
-- shift as well

tVar = getAt(sprite(1).scriptInstanceList, 1, 1)
call(#bumpCounterH, tVar, 567,890,765)
-- works fine

--------------

Source(http://www.peb965.cv.ua/list_questions/dir/scriptInstanceList.dir)



TIA
peb965



[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]


--

Multimedia Wrangler.

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to