dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How to dynamically create textarea component?

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    7

    Question How to dynamically create textarea component?

    Hi guys, I'm a novice action script programmer so easy on me .

    I have got an array full of strings and I want to populate the elements into dynamically created textarea components. I have seen "this []" syntax used to dynamically create arrays, but I can not get something similar to work for text area components.

    Here is the code that I am trying:


    Code:
    	
            for (var i:int = 0; i < aActivities.length; i++) {
    
    	this["taNode_" + i] =  new TextArea();
    	this["taNode_" + i].move(20,50 + (10*i));
    	this["taNode_" + i].height=26;
    	this["taNode_" + i].text=aActivities[i];
    	addChild(this["taNode_" + i]);
    	}
    I get this message when I run my movie:

    "1180: Call to a possibly undefined method TextArea."

    I do have an instance of a textarea in my Library as I know you have to for things like data grid.

    Any suggestions would be greatly appreciated.

  2. #2
    Junior Member
    Join Date
    Jul 2009
    Posts
    2
    place:

    import fl.controls.TextArea;

    at the top of your script

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Once you get that working, try replacing the sequential naming convention with a proper array:
    Code:
    var textareas:Array = new Array();
    for (var i:int = 0; i < aActivities.length; i++) {
    	var ta:TextArea =  new TextArea();
    	ta.move(20,50 + (10*i));
    	ta.height=26;
    	ta.text=aActivities[i];
    	addChild(ta);
            textareas.push(ta);
    }

  4. #4
    Junior Member
    Join Date
    Aug 2009
    Posts
    7
    Quote Originally Posted by whenqtipsattack View Post
    place:

    import fl.controls.TextArea;

    at the top of your script

    Dude, I feel like such a blonde. Many thanks for pointing that out.

    5TonsOfFlax: thanks for the suggestion, I tried to do sometime similar before but that did not work probably because of the missing import.

  5. #5
    Captain
    Join Date
    Oct 2005
    Posts
    63
    Also, the component (textArea) should be dragged from its habitat in the components window into your project library.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center