|
From: Bob220867 on 10 Apr 2008 04:29 Thanks for those replies. Very helpful. Thanks CenturyMan for the cleaning up observation, I'm always trying to make my scripting more efficient. This code is from a larger behaviour and one of the bits you don't see here is 'my=sprite(me.spriteNum)'. It's a shame about naming, that would have been really useful. I think I've come to a dead end on this attempt. The reference to scriptInstanceList in the 8.5 Lingo Dictionary says 'It can be set only if the sprite already exists and has at least one instance of behaviour already attached to it'. So that goes against my scripted sprite, doesn't it? Unless that's just out of date. If anyone has any good ideas for this I'd grateful, otherwise it's back to making lots of unique cast members with scripts, which obviously for the sake of elegance and time I wanted to avoided. Thanks again.
From: Mike Blaustein on 10 Apr 2008 08:52 I have had success with making a scripted sprite (using the makeScriptedSprite() method), then adding a script to it using the sprite's scriptInstanceList. In fact, my code specifically checks to see if the scriptInstanceList.count=0 before adding the new one. It will only apply the script if the sprite has no other scripts attached.
From: Bob220867 on 10 Apr 2008 11:25 Thanks for responding Mike. I'll twiddle a bit more before abandoning this. Was the code you used so much different from what I have?
From: Mike Blaustein on 10 Apr 2008 11:45 Nope. It was quite similar. Apart from the fact that I was checking to see if the sprite's scriptInstanceList was empty before adding it, and the script I gave it was an instance of a parent script. But your code looks like it should work (apart from the sprite naming thing of course)
From: CenturyMan1979 on 10 Apr 2008 11:49 Your code should work since I took what you gave us and modified it slightly to make it work. I took the createPiece function and just stuck it in a movie clip and then just put a button on the screen that would call that function. Then after setting your my referenced variables to static ones since I was not sure on the values it seemed to work fine. The sprite naming still does not seem to be working but I don't get an error when trying to name it. I will attach the code I made, -- Movie Script global i on startMovie() set i = 0 end startMovie on createPiece() -- iterate i that is method of naming sprites i=i+1 -- set sprite channel variable myChannelNum=_movie.lastChannel-i -- set up ref point for new piece origLoc=_mouse.mouseLoc --origLoc=my.loc -- make a copy of the play piece stageImage=(the stage).image spriteimage=stageImage.crop(rect(0,0,100,100)) --spriteimage=stageImage.crop(my.rect) -- set up new play piece member pMember=_movie.newMember(#Bitmap) pMember.name="NewPiece"&&i pMember.image=spriteImage -- set up sprite channel for new play piece member channel(myChannelNum).makeScriptedSprite(pMember, origLoc) sprite(myChannelNum).moveableSprite = TRUE sprite(myChannelNum).scriptInstanceList.add(script("dynPieceScript")) sprite(myChannelNum).name = pMember.name -- myNewSprite.name=my.member.name&&i end createPiece -- Button Script on click(me) createPiece() end click
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: CAPITAL letters Next: Sprite Toolbar on Score not working anymore |