A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: filling textfields with AS3

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Location
    UK
    Posts
    6

    filling textfields with AS3

    Hi all, I apologise if this is a really daft query, but I've been searching everywhere and not quite finding what I need to (in a way that makes any sense to me, at any rate!) I'm pretty experienced with AS2, to the point where I've programmed simple flat-shaded 3D engines, and isometric 3D game engines, but I've only just had to start learning AS3 (I know, I know). Basically the company I worked for didn't want to spend any money and we've been on old pre-as3 versions of flash for years and years. Only now I need to get up to speed fast for a new job.

    Here's a basic example I'm having problems with. I'm trying to figure out how to fill a textfield on stage using an external as3 file. The whole 'class' thing. I've got to do a load more complicated stuff parsing data that will go into the text field, but when it comes to the 'complicated' stuff, the differences aren't too bad between as2 and as3 and I'm finding that the easy part. I just can't figure out how the hell to get the external as3 file to even do something as absurdly simple as putting text into a text field.

    I've got an .fla called test1 with a text field just called 'sometext'. Then I've got an external as3 file called test1.as. I've linked this to the fla using the fla's document properties, (so that has 'class: test1'). In my test1.as file I have this...

    package {
    import flash.text.TextField;
    public class sometext extends TextField
    {
    var sometext.textField
    public function test1() {
    // constructor code
    sometext.text="hello";
    }
    }
    }

    I know that's wrong, but I don't know what the heck to put instead, and the error text is about as helpful as a halfwit drunken turnip trying to teach me swedish. What examples I have found all seem to deal with generating the textfield itself in the code, but if I do that but then simply leave out the code generating the textfield in order to use the existing one, everything stops working. Any help would be much appreciated!!!
    Thanks in advance...

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Maybe try something like this...
    Code:
    // In the action script settings, for Stage: check, Automatically declare stage instances
    
    package  {
            import flash.display.*;
            import flash.text.*;
    
            public class test1 extends MovieClip {
    
                    public function test1() {
                            sometext.text="hello";
                    }
            }
    }

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Location
    UK
    Posts
    6
    Thanks very much for the help, Dawsonk! Much appreciated!

    I eventually figured out something like that with trial and error. It's just taking me a while getting my head around this whole class system thing. Well, not so much the logic behind it, as what does what where. For example, in your code you've got import flash.text.*; (which makes sense, since I'm filling a text field) but then my brain keeps saying 'so the class to extend must be the text or textfield class' until suddenly you find it's the movieclip onethat does it... I just wish it was all a bit clearer. I ended up doing a fairly complex bit of coding the other day, but spent about half an hour writing the complicated bit, and about two hours figuring what classes and extends and whatnot to use lol! I'll get there in the end... ;-)

    Thanks again!

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