Ralph Brooker
08-23-2005, 07:44 PM
I am having trouble configuring a button handler from within a method of a custom class. The onRelease method will correctly call a Trace function, but it will not seem to call any other method in the custom class that requires parameters to be passed.
I am new to Flash and AS, so if I am making a basic error, please educate me! The objective is a reasonably portable class with interactivity that I can instantiate with minimum fuss.
Thank you!
Ralph
I have the following in the main timeline actions. The button exists in the library.
var bt:ButtonTest = new ButtonTest(this);
bt.setupButton(); //Works - button appears
The class file ButtonTest.as is as follows:
class ButtonTest{
// Test setting up buttons from within a custom class
var clipName:MovieClip;
function ButtonTest(clipNameParameter){
clipName = clipNameParameter;
}
function setupButton(){
clipName.attachMovie("freq_btn","myFreq_btn", clipName.getNextHighestDepth());
clipName.myFreq_btn.onRelease = function(){
trace("In the onRelease function: Button was pressed."); //Only this works
this.testFunction("A parameter string"); //Doesn't work!
this.testFunctionAlt(); //Doesn't work either
}
}
function testFunctionAlt(){
trace("In testFunctionAlt..."); // Never gets called
testFunction("Alternative parameter string");
}
function testFunction(t:String){
trace("In testFunction: t = " + t); // Never gets called
}
}
I am new to Flash and AS, so if I am making a basic error, please educate me! The objective is a reasonably portable class with interactivity that I can instantiate with minimum fuss.
Thank you!
Ralph
I have the following in the main timeline actions. The button exists in the library.
var bt:ButtonTest = new ButtonTest(this);
bt.setupButton(); //Works - button appears
The class file ButtonTest.as is as follows:
class ButtonTest{
// Test setting up buttons from within a custom class
var clipName:MovieClip;
function ButtonTest(clipNameParameter){
clipName = clipNameParameter;
}
function setupButton(){
clipName.attachMovie("freq_btn","myFreq_btn", clipName.getNextHighestDepth());
clipName.myFreq_btn.onRelease = function(){
trace("In the onRelease function: Button was pressed."); //Only this works
this.testFunction("A parameter string"); //Doesn't work!
this.testFunctionAlt(); //Doesn't work either
}
}
function testFunctionAlt(){
trace("In testFunctionAlt..."); // Never gets called
testFunction("Alternative parameter string");
}
function testFunction(t:String){
trace("In testFunction: t = " + t); // Never gets called
}
}