Hi all,

I've been playing around with filmloops again lately and I've come up with a
way for behaviours in a filmloop to register their host sprite during the
beginsprite event. Maybe someone else has done this already but I haven't
seen it. So, I thought I'd share this with the list since it would further
help out Ian Johnson in his bitmap clipping work.

Basically the big problem with filmloops is that if you want a sprite to
change one of its properties like ink or width etc. you can't simply say
sprite(me.spriteNum).ink=36, because the code ends up targeting the stage,
this isn't a problem with LDMs since they are autonomous in most respects.
Since filmloops are tied directly with the stage if you want a filmloop to
change the properties of one of its sprites you have to get the sprite in
the filmloop to tell the filmloop's host sprite to tell the sprite to change
its property, sound confusing?:

If sprite 10 contains a filmloop which has a sprite in channel 5 which when
clicked on has to change its locH by +5 then the code embedded in the
filmloop on sprite 5 would be:

property pMySprite

on beginSprite me
    pMySprite=sprite(me.spriteNum)
end

on mouseDown me
    tell sprite(10)
        pMySprite.locH=pMySprite.locH +5
    end tell
end

The problem is what happens if the filmloop is to be in another channel or
you want multiple instances of the filmloop in different channels. You can't
hard code "sprite(10)". So as a solution in the past I've limited filmloop
actions to ones where I get the action to occur on the filmloop and then
pass along the reference to the host sprite in a sendAllSprites command (
for an example see the earlier clipping code I posted) or the actions
contained no sprite referencing at all. BUT there is a way to get around
this. It is possible for every behaviour attached to sprites within a
filmloop to find out there host sprite during their  beginsprite event.

On the hostSprite put the following behaviour:

on mHostSpriteTest me, aSprite, aTestProp
  tell sprite(me.spriteNum)
    return aSprite[aTestProp]
  end tell
end

Then in any behaviours to be used within a filmloop follow this structure
so the mouseDown example from above becomes:

property pMySprite
property pMyHostSprite

on beginSprite me
  pMySprite=sprite(me.spriteNum)
  me.mFindHostSprite()
end

on mFindHostSprite me
  testProp=symbol("p"&string(me).word[4])
  me[testProp]=1
  repeat with i=1 to the lastChannel
    found=sendSprite(i, #mHostSpriteTest, pMySprite,testProp)
    if found then
      exit repeat
    end if
  end repeat
  me[testProp]=void
  pMyHostSprite=sprite(i)
end

on mouseDown me
    tell pMyHostSprite
        pMySprite.locH=pMySprite.locH +5
    end tell
end


Hopefully I haven't wasted too much bandwidth with this and I know that Ian
at least will find it useful.
If anyone else gives this a try I'd be curious to hear how it works out for
them.

later,

Rob


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/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