Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2005
    Location
    greater manchester, uk
    Posts
    65
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question altering textfield on stage from within a class

    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)


    Code:
    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:


    Code:
    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...
    Code:
    trace(m_arrNews[0]);
    ...then I get exactly the value that I'm expecting.




    However, the line...
    Code:
    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
    Last edited by MattyJim; 04-03-2008 at 01:08 AM.

  • #2
    New Coder
    Join Date
    Mar 2005
    Location
    greater manchester, uk
    Posts
    65
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Thumbs up solved

    Ok, panic over; I figured it out.



    For anybody who's interested, I changed...
    Code:
    //pass a reference to the stage
    Graph.stageRef = this.stage;
    ...to...

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

  • #3
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Nice work
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •