As you can see, I’m trying to set the previousClip variable (which belongs to the Scratch-class) in the onMouseUp function. I know I’m not doing it the right way, but can someone tell me how to set a the previousClip variable properly? Thanks!
well that and you posted it at around 1:00 AM K-Time which isnt a very active time for the board
For one thing, its typical NOT to define functions in a class constructor, this especially if you plan on having more than one instance of that object. Using prototypes will allow you to distribute one function to each instance - like a shared function (its good practice too) ie.
Now, the problem you’re having (if you’re doing what I think you’re doing) is that you are losing scope of the real previousClip when you are in your onMouseUp. The reason for this is because the scope in that onMouseUp is then the scope of whatever the currentClip is and not your Scratch object. Saying this.previousClip wont do it because that would reference currentClip’s previousClip. Saying just previousClip wont work because that will be looking for previousClip either within that function (which is non existant), the scope in which that code is written (_root?) followed by _global, respectively. Since previousClip does not exist in any of those scopes, its nothing and ends up being defined for the scope in which that code is placed if uses as in the example above. However, what you need is the scope of the Scratch object. We have that scope Before the onMouseUp, but not in it. So what you can do is set a variable in that local function scope to represent that Scratch object, and then reference that in the onMouseUp like so:
So here, this in the Scratch object scope is assigned to a local function variable called me. That is then referenced in the currentClip.onMouseUp in obtaining the previousClip. Because me is now that Scratch object, saying me.previousClip in that onMouseUp then references that actual Scratch object and assigns its previousClip to be the clip that was pressed.
In that I also made currentClip local to the function (otherwise it would be making that variable in the clip you wrote the code (_root?)) and used associative array syntax to get the clipName movieclip. Its less typing and is a little cleaner
… come to think of it, dont you want an onRelease?
onMouseUp is a global mouseUp for when ever the mouse is pressed ANYWHERE, not just on that movieclip, whereas onRelease is when you press and release on that actual clip. I really dont know how you have things set up - it could very well be onMouseUp, but its common to get those two confused
I keep hitting myself on the head for not coming up with that myself, because I’m sure I read it in my “Object Oriented Programming with ActionScript” book, that’s just sitting on my shelf, collecting dust.
…Also, I didn’t know onRelease could be assigned to a movieclip instance. I’m gonna have to try that