3 Replies Latest reply on Aug 27, 2007 6:21 AM by SymTsb

    Beginner Actionscript 3.0 Help

    Bob Ralian
      I'm just trying to get a dynamic text field to be populated by "Hello World" using actionscript 3.0.

      My flash file has a dynamic text field named "randomtext" on frame 10 of a layer also named "randomtext". My understanding is adding this name to a dynamic text field automatically turns it into an object that can be manipulated with actionscript. In a separate layer called "actions" I have added some actionscript at frame 1 that says:

      import flash.text.TextField;
      randomtext.text = "Hello World";

      However, when I test the movie (using control>Text Movie), I get the following error:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at cookie_fla::MainTimeline/cookie_fla::frame1()

      When I remove that actionscript code, the error goes away. Am I missing some other step?
        • 1. Re: Beginner Actionscript 3.0 Help
          Damon Edwards Level 3
          you are trying to apply the script before the text field instance appears on stage. add the actions onto the frame above where the text field is located.
          • 2. Re: Beginner Actionscript 3.0 Help
            Bob Ralian Level 1
            That makes sense. I tested a simpler version of my movie all on one frame and it worked. It seems odd to me that all of the variables are not available to the movie until you get to them in the timeline. I would think you'd want the number/script-crunching to happen at the beginning, rather than in the middle where it could potentially interfere with the speed of the movie. I'll probably just do what you suggested, but I'm curious. Is there a way to instantiate the auto-variables (textfields, whatnot) at the beginning so you can begin manipulating them immediately?
            • 3. Re: Beginner Actionscript 3.0 Help
              SymTsb Level 2
              Actionscript is handled in a top down frame by frame basis and always handled in the compiler before the graphics are drawn to the screen. The only way to instantiate at the beginning would be to dynamically code the text field in frame one and add it to the display list when you need it.