I am working with an extended class that has a text event handler in it, all of this works perfectly but I need to have communication with classes that extends this class. How is this done?
Example:
ContentView extends BasicContentView
How can BasicContentView trace a variable in ContentView? Can this be done?
In the BasicContentView I do a trace(parent) and it reads ContentView but If I try and read a variable in Content view I get this error:
1119: Access of possibly undefined property tempString through a reference with static type flash.display:DisplayObjectContainer.
So you want to access a variable that is declared in ContentView from BasicContentView? No you can’t do that because all BasicContentView knows about is what it extends and imports, and what is in that class. But why do you need to do this? There’s probably a better way to do that. If you show me the code that your trying to implement I can help you better.
That makes sence from your post and from reading up alittle on the topic. I can do it by removing the TextFeild code out of the BasicContentView and into each class that needs it. I just like grouping up code that I need more than once. Maybe you can show me a better a way. - Thanks
Here is a simplified version of the code I am working with:
package sbTestSide{
import flash.display.Sprite;
internal class TestTypeView extends BasicContentView{
public function TestTypeView() {
createTextFormat(aTextFormateProp[0], aTextFormateProp[1], aTextFormateProp[2], aTextFormateProp[3], "Type a question here", "QuestionTB");//x, y, width, height, text
}
}
}
package sbTestSide{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFieldType;
import flash.text.TextFormatAlign;
import flash.events.*;
internal class BasicContentView extends Sprite {
internal var tText:TextField;
internal var qText:TextField;
public function BasicContentView() {
//
}
//Create Text Field ------------------------------------------------------------------------------------------
protected function createTextFormat(xLoc:Number, yLoc:Number, wWidth:Number, hHeight:Number, sText:String, sTBName:String):void{
qText = new TextField();
qText.type = TextFieldType.INPUT
qText.x = xLoc;
qText.y = yLoc;
qText.width = wWidth;
qText.height = hHeight;
qText.selectable = true;
qText.border = false;
qText.wordWrap = true
qText.multiline = true;
qText.tabEnabled = true;
qText.addEventListener(Event.CHANGE, textChanged);
qText.name = sTBName;
//qText.autoSize = TextFieldAutoSize.LEFT;
var Format:TextFormat = new TextFormat();
Format.font = "Arial";
Format.color = 0x00000;
Format.size = 12;
qText.defaultTextFormat = Format;
qText.text = sText;
addChild(qText);
//Event-------------------------------
function textChanged(event:Event):void{
trace(event.target.text);
if(qText.name == "QuestionTB"){
//** This is the line that I need to run**
//parent.parent.parent.wsWebService.setXMLTestQuestions(event.target.text)
trace("1");
}else if (qText.name == "AnswerTB"){
trace("2");
}else if (qText.name == "YourAnswerTB"){
trace("3");
}
trace("qTextName= "+qText.name);
}
}
}
}
You don’t declare anything in TestTypeView, so what could you possibly reference from BasicContentView that is in TestTypeView? Anyways, if you want to access a property from the parent class you should declare it in the parent class since it will be unanimous with all classes that extend it right? If it’s specialized to the class you need to have class specific code to deal with it.