how to populate txt within movieclip created using duplicatemovieclip command
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: how to populate txt within movieclip created using duplicatemovieclip command

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Posts
    117

    how to populate txt within movieclip created using duplicatemovieclip command

    i have amovie clip on stage with a text field inside it.

    i want to create multiple movie clips using duplicatemovieclip command and in each i want to popluate the text field with different text.

    Code:
    for(m=0; m < 5; m++)
    	{
    		if (m==0){
    			cat.name_txt.htmlText="first";
    			cat._y=50;
    		}
    		else
    		{
    			duplicateMovieClip (cat, "cat" + m+1, m+1);
    			newname = "cat" + m+1;
    			//trace (newname);
    			newname.name_txt.htmlText="crap";
    			newname._y = 50*(m+1);
    			trace(newname._y);
    			
    		}
    only the first is being displayed....plz guide with this code ...i think i m making a mistake in the newname method of addressing the movieclips created using the duplicate command

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,091
    Hi,

    You can try something like this, its easy enough to decipher

    PHP Code:
    var Names:Array = ["first""crap""fart""idiot""smelly"];
    var 
    NumberRequired 5;

    for (var 
    0NumberRequiredm++)
    {
        
    duplicateMovieClip("cat""cat" mthis.getNextHighestDepth());
        
    this["cat" m]._y 50 * (1);
        
    this["cat" m]._x 100;
        
    this["cat" m].name_txt.htmlText Names[m];
        
    this["cat" m].onRollOver = function(){
            
    trace(this._name " - " this.name_txt.htmlText);
        };

    Last edited by fruitbeard; 01-18-2013 at 06:16 AM.

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    below is my code

    Code:
    var countcategory:Array = shoplistXML.firstChild.childNodes;
    
    for (i=0;i<category.length;i++)
    			{
    			categoryname[i]=shoplistXML.firstChild.childNodes[i].attributes.name;
                            }
    
    
    
    for(m=0; m < countcategory.length; m++)
    	{
    		if (m==0)
    		{
    			catname.catname_txt.htmlText=categoryname[m];
    			catname._y=50;
    		}
    		else
    		{
    			duplicateMovieClip("catname", "catname" + m, this.getNextHighestDepth());
        		this["catname" + m]._y = 50 * (m + 1);
        		this["catname" + m]._x = 300;
        		this["catname" + m].catname_txt.htmlText = categoryname[m];
    			trace (this["catname" + m].catname_txt.htmlText);
    			trace (categoryname[m]);
    			//this["cat" + m].onRollOver = function(){
           			//this["catname" + m].catname_txt._color=0x555555
        		//};
    			
    		}
    the trace categoryname[m] traces the name correctly...

    but the line trace (this["catname" + m].catname_txt.htmlText); is tracing as undefined

    what am i doing wrong

    xml is

    Code:
    <content>
    
    	<category name="fruits">
    		<item>1</item>
            </category>
    
           <category name="veg">
    		<item>2</item>
            </category>
    
           <category name="non-veg">
    		<item>3</item>
            </category>
    
    </content>
    Last edited by glassfairy; 01-19-2013 at 02:39 AM.

  4. #4
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    below is my FULL code

    Code:
    stop();
    var shoplistXML:XML = new XML();
    shoplistXML.ignoreWhite=true;
    
    var m:Number =0;
    
    var categorynum:Array = new Array();
    var categoryname:Array = new Array();
    
    
    shoplistXML.onLoad= function(success) 
    {
    	if (success) 
    	{
    		var countcategory:Array = shoplistXML.firstChild.childNodes;
    		var category:Array = shoplistXML.firstChild.childNodes;
    		
    				
    		
    		for (i=0;i<category.length;i++)
    			{
    			categoryname[i]=shoplistXML.firstChild.childNodes[i].attributes.name;			
    			}
    	
    				
    	for(m=0; m < countcategory.length; m++)
    	{
    		if (m==0)
    		{
    			catname.catname_txt.htmlText=categoryname[m];
    			catname._y=50;
    		}
    		else
    		{
    			duplicateMovieClip("catname", "catname" + m, this.getNextHighestDepth());
        		this["catname" + m]._y = 50 * (m + 1);
        		this["catname" + m]._x = 300;
        		this["catname" + m].catname_txt.htmlText = categoryname[m];
    			trace (this["catname" + m].catname_txt.htmlText);
    			trace (categoryname[m]);
    						
    		}
    		
    		
    	}
    		
    	}
    }
    
    
    
    shoplistXML.load("shoplist_gallery.xml");
    the trace categoryname[m] traces the name correctly...

    but the line trace (this["catname" + m].catname_txt.htmlText); is tracing as undefined

    what am i doing wrong

    xml is

    Code:
    <content>
    
    	<category name="fruits">
    		<item>1</item>
            </category>
    
           <category name="veg">
    		<item>2</item>
            </category>
    
           <category name="non-veg">
    		<item>3</item>
            </category>
    
    </content>

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,091
    Hi,

    I don't do xml, but the line
    trace (this["catname" + m].catname_txt.htmlText);

    should probably be

    trace (this["catname" + m].catname_txt.text);

    Try attaching your fla so people don't need to try and create new files to act and work like yours.

    P.s. Please don't private message telling me to look at your new post

  6. #6
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    it doesn't work

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,091
    Hi,

    This will work for you
    PHP Code:
    stop();
    var 
    shoplistXML:XML = new XML();
    shoplistXML.ignoreWhite true;

    var 
    m:Number 0;

    var 
    category:Array = new Array();
    var 
    categoryname:Array = new Array();

    shoplistXML.onLoad = function(success)
    {
        if (
    success)
        {
            var 
    category:Array = shoplistXML.firstChild.childNodes;
            for (
    0category.lengthm++)
            {
                
    categoryname[m] = shoplistXML.firstChild.childNodes[m].attributes.name;
                
    duplicateMovieClip("catname""catname" m_root.getNextHighestDepth());
                
    _root["catname" m]._y 50 * (1);
                
    _root["catname" m]._x 300;
                
    _root["catname" m].catname_txt.htmlText categoryname[m];
                
    trace(_root["catname" m].catname_txt.text " - " _root["catname" m]._name);
            }
        }
    };

    shoplistXML.load("shoplist_gallery.xml"); 
    but you are better off duplicating a clip that is off stage, the first one made it awkward to manage.
    you could always attachmovie clip instead from the library, but this works.

  8. #8
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    yes the _root worked!

    it traces correctly now but the movie clip is not created on stage

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,091
    Hi,

    Attach your fla file so I/we can take a proper look at the set up.
    My version works flawlessly but is probably different to yours.

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,091
    Hi, as you are here now, post your fla or did you get it sorted?
    Perhaps you need to have the movie clip you need duplicating on stage (or off stage at least). otherwise you will need to use attachmovieclip

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

Poll by Flashkit.com