...

View Full Version : altering textfield on stage from within a class



MattyJim
04-03-2008, 12:59 AM
Hello!


I'm new to actionscript (I'm using AS3, by the way), so please forgive me if I get my terminology mixed up:




I have a couple of textfields name "txtTest0" and "txtTest1" on the stage.


I'm using the following code to read delimited values from a .php script and into an array, which I then pass into an AS3 class (custData.graph)




import custData.graph;

//Create the URLLoader instance
var myLoader:URLLoader = new URLLoader();

//the data will come as URL-encoded variables
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

//Load using an URLRequest, even beeing local
myLoader.load(new URLRequest("http://localhost:81/mattyjim_proj/ajax_script.php"));

//onLoad handler listener
myLoader.addEventListener(Event.COMPLETE, onDataLoad);

//add a listener for the complete event
function onDataLoad(evt:Event)
{
var arrData:Array = new Array();

for(var i:uint=0; i<2; i++)
{
arrData.push(evt.target.data["xxx"+i]);
}

var Graph:graph = new graph();
Graph.newsData = arrData;
//pass a reference to the stage
Graph.stageRef = this.stage;
Graph.init();
}





My graph class is as follows:




package custData
{
public class graph
{
private var m_stageRef:Object = new Object;
private var m_arrNews:Array = new Array();


public function set newsData(value):void
{
m_arrNews = value;
}

public function set stageRef(value):void
{
m_stageRef = value;
}

public function init():void
{
//trace(m_arrNews[0]);
m_stageRef["txtTest0"].htmlText = m_arrNews[0];
}

}

}




Passing the array into the class works just fine. If I do...


trace(m_arrNews[0]);

...then I get exactly the value that I'm expecting.




However, the line...


m_stageRef["txtTest0"].htmlText = m_arrNews[0];

..throws an error "Error #1069: Property txtTest0 not found on flash.display.Stage and there is no default value"



I want to write the array values into my text fields, but I don't seem to be able to access objects that are on the stage properly.

Does anybody have any idea where I might be going wrong with this?



Any help would be greatly appreciated.


Thanks :)

MattyJim
04-03-2008, 02:17 AM
Ok, panic over; I figured it out.



For anybody who's interested, I changed...


//pass a reference to the stage
Graph.stageRef = this.stage;


...to...



//pass a reference to the stage
Graph.stageRef = this.root;

gnomeontherun
04-03-2008, 08:18 AM
Nice work:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum