Here's my guess about your problem, and a potential fix. The problem has to do with the value of "spriteNum". When you use a behavior normally (attached during authoring), the special property variable spriteNum is automatically given the corrent value. All you have to do is to declare spritenum as a property, and it will be given the value of the channel number of the sprite.

However, if you attach a behavior "on the fly", this assignment does not happen. To fix this, you can do it in your code. I see below that you are creating an instance of the cursor script by doing this:

xCursor = (script "flaCursorScript").new(2)

However, you don't show your "new" handler in the behavior. I'll bet that you can fix this problem by doing this:

property spriteNum

on new me, whichChannel
  spriteNum = whichChannel  -- assign spriteNum here
  -- anything else you want to do here
  return me
end

Then just use spriteNum in your exitFrame handler (and you don't need your beginSprite handler).

Or, if you like using your spriteRef variable, you can have your new method just do this instead:

on new me, whichChannel
  spriteRef = whichChannel
  -- anything else you want to do here
  return me
end

Irv


At 4:08 PM +0200 9/11/03, Kristian wrote:
Hi,

Below I have attached some simple code... The purpose with the code is to
(at runtime) be able to attach a behavior to a puppeted sprite containing a
flash member. The code works as long as I do not use the 'pSpriteRef'
variable and say instead type '2' or '3' (in the exitFrame handler in the
BEHAVIOR CODE below)... Unfortunately this will not work for me because this
behavior will be attached to more than one sprite (and the purpose of using
a behavior would be lost if I need to hardcode object references)... The
error message complains about the #hitTest which to me sounds like it does
not recognize the sprite as a flash sprite.

Anyone? Suggestions?

//Kristian


-- PART OF MOVIE SCRIPT CODE puppetSprite 2, TRUE sprite(2).member = puppetName sprite(2).width = 220 sprite(2).height = 491 sprite(2).locH = 5 sprite(2).locV = 76 if member(puppetName).loaded = TRUE then flaSetActiveSubItem(gAMemList.aSubMain,gAMemList.aSubSub, AMemList.aCastPage) end if xCursor = (script "flaCursorScript").new(2) sprite(2).scriptInstanceList.Add(xCursor)


-- BEHAVIOR CODE property spriteNum, pSpriteRef

on beginSprite me
        pSpriteRef = me.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


[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