Ok, thanks all... He code below is very useful if you just want to attach a
behavior on the fly, to a puppeted sprite that holds a flash member, for
showing the regular "hand mouse-overs" on the flash buttons. Any
comments/lessons that can optimize this/my coding is appereiciated (like
de-attaching).

This worked for me:

-- CODE FOR ATTACHING BEHAVIOR
xCursor = (script "flaCursorScript").new(num)
sprite(num).scriptInstanceList.Add(xCursor)
sendSprite(num, #beginSprite)


-- BEHAVIOR CODE
property spriteNum, pSpriteRef

on new me, whichChannel
  spriteNum = whichChannel
  return me
end

on beginSprite me
  pSpriteRef = spriteNum
end

on exitframe me
  if sprite(pSpriteRef).hitTest(the mouseLoc) = #button then
    if sprite(pSpriteRef).cursor <> 280 then
      sprite(pSpriteRef).cursor = 280
    end if
  else
    if sprite(pSpriteRef).cursor <> -1 then
      sprite(pSpriteRef).cursor = -1
    end if
  end if
end


> Okay I re-read your and Kristian's posts.
> 
> There should be no problem with the me reference if you add 
> code such as
> 
> put me
> 
> you will see that a proper reference to me is output 
> 
> The problem stems from the fact that both of you were 
> creating a new script 
> instance with the new() command. Behaviours work in such a 
> way that when they 
> are dropped on a sprite and then are instantiated the 
> automatically create a 
> property called spriteNum and assign the current sprite 
> number to it. However 
> when you call the new() event on the script no such 
> automation occurs. You can 
> get around this by forceably creating a the spriteNum 
> property after call the new()
> 
> x = script("whatever").new()
> x[#spriteNum] = theNumber
> 
> Craig in my example the spriteNum is hard coded because it is 
> communicating to 
> another sprite, I could have used sendAllSprites and it would 
> have worked. Also 
> all the instances in the scriptInstanceList will have their 
> spriteNum defined since 
> they were instantiated under regular circumstances so if in 
> the alert line you add
> 
> me.spriteNum
> 
> you'll see that the correct reference shows up. No problems 
> at all. If you explore 
> this in the future and still have problems send me a code 
> sample I know I can 
> make it work.
> 
> hth,
> 
> Rob
> 
> 
> 
> 
> 11/09/2003 11:42:12 AM, "Craig Taylor" 
> <[EMAIL PROTECTED]> wrote:
> 
> >Hey Rob,
> >
> >> on mouseDown me
> >>   pCounter = pCounter + 1
> >>   if pCounter mod 2 then
> >>     pSL = sprite(1).scriptInstanceList
> >>     sprite(1).setNum(random(100))
> >>     sprite(1).scriptInstanceList = []
> >>   else
> >>     sprite(1).scriptInstanceList = pSL
> >>   end if
> >> end
> >>
> >
> >Had  a similar sample that also worked fine, aong as you 
> hard-coded the 
> >spriteNum.  The problem seems to arise if you use "me" to 
> reference the 
> >sprite from where you are executing the code.  It simply fails to 
> >recognize that sprite.  I just sent a response back to Kristian, as 
> >such.  In other words, if you hardcode the spriteNum or even use 
> >sprite(the
> >currentSpriteNum) as an alternative, it works fine, as long 
> as you don't
> >reference the object??
> >
> >Weird...
> 
> 
> 
> 
> [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!]
> 


[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