|
-
Class's movieclip calling a function in it's own class
For the life of me I can't find an internet source that explains why this doesn't work. I know it's a scope problem but I know no other way around it and there must be a way to do it, I'm thinking.
I have a class. Inside this class I create a movieclip which I have a class variable link to. The movieclip is created on _root. When I click on this movieclip, I want it to call a function inside the class. Here's what it looks like.
Code:
class Whatever extends Movieclip {
private var mc:MovieClip;
public function Whatever() {
this.mc = _root.createEmptyMovieClip("rootmc",_root.getNextHighestDepth());
[code for drawing a square]
this.mc.onPress = this.doSomething();
}
public function doSomething {
[do something]
}
In the above sample, when I click on the movieclip, the "doSomething" function is not called, obviously because the movieclip is on root and has nothing to do with the class. Is there a way to do what I want to do?
-
OOP is one letter from OOPS
umm if this is what i think it is, usually the following will "fix" it:
class Whatever extends Movieclip {
private var mc:MovieClip;
public function Whatever() {
thisClass = this;
this.mc = _root.createEmptyMovieClip("rootmc",_root.getNextH ighestDepth());
[code for drawing a square]
this.mc.onPress = thisClass.doSomething();
}
public function doSomething {
[do something]
}
try it and see if that does the trick
-
No, that doesn't seem to work. It gives me an error that the property doesn't exist so I do
var thisClass = this;
instead, and then it accepts it but does not work. Maybe I need to rethink what I am doing.
-
Nevermind, that actually did work. Thank you very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|