Skip to main content
MikesNameIsMike
Inspiring
December 14, 2010
Answered

what is happening here?? TextField problem.

  • December 14, 2010
  • 1 reply
  • 1141 views

I'm not new to this and this is driving me crazy.  Can someone please look at this and tell me what I am doing wrong.  There is a Font named Arial embeded in my library, set to export for AS.  This is the relevent part of my document class.  All this does is create a textfield, add it to stage, set the text, load an xml file then attempt to change the text in the text field.  But the text does not change.

public class Main extends MovieClip {
       
        public static const EASE_TYPE: Function = gs.easing.Sine.easeIn;
        public static const XML_PATH: String = "EventData.xml";
        public static const TWEEN_TIME: Number = .5;
       
        public var _messageField: TextField;
       
        private var _xmlLoader: URLLoader;
        private var _currentIndex: Number;
        private var _messages: Array;
        private var _times: Array;      
        private var _timer: Timer;
       


        public function Main(): void {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.EXACT_FIT;
            init();
        }


        private function init(): void {
            _times = new Array();
            _messages = new Array();
            _currentIndex = -1;
           
            _messageField = new TextField();
            _messageField.selectable = true;
            _messageField.width = 955;
            _messageField.x = 15;
            _messageField.y = 0;
            _messageField.defaultTextFormat = new TextFormat( new Arial().fontName, 12, 0xFFFFFF, false, false, false, null, null, TextFormatAlign.LEFT);
            _messageField.antiAliasType = AntiAliasType.ADVANCED;
            _messageField.embedFonts = true;
            this.addChild(_messageField);
           
            _messageField.text = "Test 1 2 3 . . .";
           
                //  Load the xml file containing messages and times to display them.
            _xmlLoader = new URLLoader();
            _xmlLoader.addEventListener(Event.COMPLETE, onXMLload);
            _xmlLoader.load(new URLRequest(XML_PATH));
       
           
        }
       
        private function onXMLload(e: Event): void {
           
            trace("XML Loaded");
            _messageField.text =". . . 3 2 1 tseT";

            trace( _messageField.text);

         }

....

At this point when I run this, I get a trace of "XML Loaded" and ". . . 3 2 1 tesT"  but me text field still says "Test 1 2 3 . . ." when it should say ". . . 3 2 1 tesT"  Why would this happen?   It's as if the text field is not updating.  I wrote this project using CS4 and it worked fine. I am now opening it/running it with CS5, if that matters...

Any help would be appreciated!

This topic has been closed for replies.
Correct answer kglad

you're correct.

there should be no problem with your code.  you must be something other than the result of that code.


when i test your code i see ". . . 3 2 1 tseT" in the textfield, as expected.


1 reply

kglad
Community Expert
Community Expert
December 14, 2010

you're probably out of scope.  add your urlloader to the display list.

MikesNameIsMike
Inspiring
December 14, 2010

Hey Kglad, thanks for the response.

onXMLload() is a method of class Main and _messageField is a member of Class Main.  What specificly do think could be out of scope.  The trace statement for _messageField.text displays the new value, but the swf is still showing the old .text value.

As far as I know, you can't add a URLLoader to the display list.  It is not a display object, nor does it extend a display object.  How would I go about doing this?

kglad
Community Expert
Community Expert
December 14, 2010

you're correct.

there should be no problem with your code.  you must be something other than the result of that code.