Skip to main content
Inspiring
October 7, 2007
Answered

Flash 8 scope question

  • October 7, 2007
  • 1 reply
  • 229 views
In the following class can someone tell me how I would call the doSomething() function from within myObject.onMouseDown=function()?



class Practice extends MovieClip {
var myObject:Object;
//
public function Practice() {
myObject = new Object();
myObject.onMouseDown = function() {
// call doSomething here
doSomething();
};
Mouse.addListener(myObject);
}
//
public function doSomething() {
trace("did something");
}
}
This topic has been closed for replies.
Correct answer caseymanx
Figured it out.

class Practice extends MovieClip {
var myObject:Object;
//
public function Practice() {
myObject = new Object();
//
var me:Practice = this;
//
myObject.onMouseDown = function() {
// call doSomething here
me.doSomething();
};
Mouse.addListener(myObject);
}
//
public function doSomething() {
trace("did something");
}
}

1 reply

caseymanxAuthorCorrect answer
Inspiring
October 7, 2007
Figured it out.

class Practice extends MovieClip {
var myObject:Object;
//
public function Practice() {
myObject = new Object();
//
var me:Practice = this;
//
myObject.onMouseDown = function() {
// call doSomething here
me.doSomething();
};
Mouse.addListener(myObject);
}
//
public function doSomething() {
trace("did something");
}
}
clbeech
Inspiring
October 7, 2007
there you that's it, you just need to define 'this' outside the onMouseDown method to refer to the class scope. However there are a acouple of things you could do to streamline this a little.