dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How do I create a textfield inside a movieclip at runtime?

  1. #1
    Senior Learner garion1's Avatar
    Join Date
    Dec 2001
    Location
    South Africa
    Posts
    483

    How do I create a textfield inside a movieclip at runtime?

    I thought this would be simple, but it has proven not to be.

    I have a Movie Clip on my stage called contentMC.
    With ActionScript 2.0 I can create a textfield inside this MC at runtime using: contentMC.createTextField("contentText", 1, 0, 0, 300, 200);

    With ActionScript 3.0 I can create the same textfield using:
    private var contentText:TextField = createTextField(0, 0, 300, 200);
    but I have no idea how to create it inside contentMC?

    Please help.
    "A day without laughter is a day wasted." - Charlie Chaplin

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    it's not createTextField, it's "new TextField()" and it doesn't take any arguments. you have to assign width and height
    PHP Code:
    var contentText = new TextField();
    contentText.width 300;
    contentText.height 200;
    contentMC.addChild(contentText

  3. #3
    Senior Learner garion1's Avatar
    Join Date
    Dec 2001
    Location
    South Africa
    Posts
    483

    Thank You

    contentMC.addChild(contentText) is what I needed. Thanks.
    "A day without laughter is a day wasted." - Charlie Chaplin

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174

  5. #5
    Member
    Join Date
    Oct 2006
    Posts
    41
    I am having the same issue with AS 2.0. I tried the code you posted with no luck. When I do a search for "addChild" in the help docs, I get nothing. Stumped. Been searching the forums for a few hours now. I am creating a movieclip on the fly along with 10 fields. I then want to add XML data in each field, but I cannot even create a text field inside my movieclip.

  6. #6
    Member
    Join Date
    Oct 2006
    Posts
    41
    Code:
    this.createEmptyMovieClip("Min_Rectangle_mc", 1);
    Min_Rectangle_mc.lineStyle(1, 0x1947D1, 100);
    Min_Rectangle_mc.beginFill(0xffffff, 100);
    
    /*Top Line */
    Min_Rectangle_mc.moveTo(100, 100);
    
    /*Top right box*/
    Min_Rectangle_mc.lineTo(400, 100);
    
    /*Bot right box */
    Min_Rectangle_mc.lineTo(400, 200);
    
    /*Bot Left*/
    Min_Rectangle_mc.lineTo(100, 200);
    
    /*Top left */
    Min_Rectangle_mc.lineTo(100, 100);
    
    var contentText = new TextField(); 
    contentText.width = 300; 
    contentText.height = 200; 
    contentText.text = "test"; 
    Min_Rectangle_mc.addChild(contentText) 
    
    Min_Rectangle_mc.endFill();
    Min_Rectangle_mc.onPress = function() {
        this.startDrag();
    };
    Min_Rectangle_mc.onRelease = function() {
        this.stopDrag();
    };

  7. #7
    Member
    Join Date
    Oct 2006
    Posts
    41
    So found something which works. Apparently, I need to refer to the text as an array object element using square brackets. I never would have figured this out except for searching. How do people figure this out. I do not see where it is documented in the help docs for AS 2.0 etc.

    Code:
    var name = "myTextField";
    Min_Rectangle_mc.createTextField(name,50,10,50,550,25);
    Min_Rectangle_mc[name].text = "hello world";

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