This content has been marked as final. Show 7 replies
posting some code would help a lot
Word of Mouth Productions
"FotoArt" <FotoArt@theMaldives.com> wrote in message
> hello everyone
> Im having 2 problems with my code
> 1 - when I add a parent script to the scriptinstance list of a sprite I
> find that the list does not show the instance of the behaviour attached to
> the sprite. therefore the behaviour is not working.
> The other problem is
> 2 - I am creating an instance of a parent script in a beginSprite event.
> But when I type "put myObj" (where myObj is the variable holding the
> instance) in the message window it gives a VOID, which means the object is
> not available to the sprites.
> any help would be appreciated.
1. Objects go into the scriptinstancelist (instance objects, script objects etc) -- not script cast members. Scripts cast members can be attached to a sprite's scriptList, along with starting parameters. When you drag a behaviour (a kind of script castmember) on to a sprite, the script is added to the 'scriptlist'. You can also add parent scripts (you cannot drag them on to the sprite though, you have to use the setScriptList() lingo function). Scripts in the script list are automatically instantiated when the sprite is created. Its hard to tell from your description whether you are trying to add instances to the scriptinstancelist or scripts to the scriptlist.
2. Assuming your code looks like this
-- this is a script (eg a behaviour) on the sprite
on beginSprite (me)
myObj = script("Some Parent Script").new()
If this is what you are doing (and as Craig said - posting some code helps), and you are getting VOID immediately after instantiating your script, then one of the following might be causing the problem:
a) Your parent script has an "on new" method that does not return a reference to the object. Eg
on new (me)
return me -- need to return 'me'
b) You have a movie script somewhere that defines an "on new" function. Movie script functions are 'global' and this will over-ride the built in new() function\.
If myObj contains a reference to the object immediately after calling new(), but is void elsewhere in the script, then you will need to declare myObj to be a property.
I have 3 scripts, (they are very awkward)
and a behaviour
myObj is Void and when I clicked a sprite its says handler not defined
I have tried creating the myObj instance in a beginsprite handler attached
to a sprite on the first frame.
when that happens mouse clicks are ignored.
on new me
on mButtonClicked (me, btnName)
alert (#"u clicked "& btnName)
myChannelList = 
repeat with i = 1 to the lastChannel
if channel(i).name = "goForward" or channel(i).name = "goBackward" then
on addToScriptInstanceList me
repeat with j in myChannelList
myObj = Script("myScript").new()
========behaviour on two sprites===========
btnName = sprite(me.spriteNum).member.name
call(#mButtonClicked, me, btnName )
any guidance will be appreciated
I'm not entirely sure what's going on, but I don't think you can use
properties in a movie script. Change the myObj declaration to a global
and see if it works a little better.
Im trying to create a parent script containing two lists. So that I can
manage/share/access the lists via two sprites on the stage - a back button
and a forward button.
Hope someone could give me some ideas on this.
I have few problems like attaching the scriptInstanceList and passing
messages from mouse events to the Pscript.
Any help would be appreciated.
Theres a couple of problems I can see:
1. The movie script.
Movie scripts can have properties. However, you don't want to declare it in your script. Director has some strange idiosyncratic ways of handling scope with movie script properties (which is the reason you get 'void' when you put myObject). If you delete the 'property myObject', your movie script will be fine. Note - you do not need to store a reference to the object you create in the movie script because an instance gets stored in the sprite scriptInstanceList. As long as you keep an instance to an object somewhere, the object will live.
2. The behaviour
The lingo line "call(#mButtonClicked, me, btnName )" will probably error since 'me' is an instance of the behaviour and the behaviour has no mButtonClicked method. Try changing it to
sendSprite(me.spriteNum, #mButtonClicked, btnName)
This sends the #mButtonMethod to all instances attached to the sprite. Alternatively, you could call the scriptInstanceList of the sprite (same effect) like this
call(#mButtonClicked, sprite(me.spriteNum).scriptInstanceList, btnName )
3. The Parent Script.
Should work - but as a rule, you should specify the scripts you are sending messages to. So, instead of writing this:
on new me
on new me
Incidentally, it seems like a long convoluted approach. IS there any reason you just don't use a single behaviour?
> Theres a couple of problems I can see:
In an attempt to keep grammar alive...
"There are a couple of problems..."
It might not be Lingo related other than the fact that it's the syntax of