Sadistic textfield writes text over previous update weirdness

Hello! Hehehe… I’m losing my mind over this problem…
Hehehe… I burned my eyes out looking for a solution, and I think there was only one guy on this forum who had similar bug like me, but he was told off that textfield shouldn’t behave in this way and thats all. So, maybe something changed and maybe someone found a solution in the meantime… Here it goes.

I tried something which was very simple in AS2, attaching dynamic movieclip and then attaching dynamic textfield inside that MC, which should update on progress event for loading an image, displaying percentage of loading done. Surprisingly, I have no problem with displaying accurate percentage info, my problem is this: most of the updates of textfield.text writes itself OVER the old text, instead of replacing it. Hehehehehe, LOL! You get it? It behaves like I create new textfield over the old one each time I update text. And I’m sure the code is not recreating textfield or MC, at least I’m positive thats not what I told it to do. So although I’m a bit new to AS3, and may probably doing something wrong, I’m getting more and more suspicious that this is a bug within flash itself, the thing that should not be.

It will be hard for me to recreate the code here, as I tried many different things in the meantime, so I’ll just show bits of latest version which doesn’t create totally dynamic MC and textfield, but attaches dynamically MC containing textfield which is inside library. The problem remains the same, and I’m sure I compile/upload latest swf version and clean browser cache everytime…


     //btw, timeline is public static MovieClip, which is like root,
//and containerMC is public static MovieClip which is attached separately
//Also if you see something without being declared as var, be sure its a static property declared in class

//func called after thumbnail button is clicked to open image
                public static function prepareImageOpen(imgObj:Object)
        {
                 //if an image is already open, fade it out, then proceed to initiate
            if(timeline.contains(containerMC))
            {
                Gallery.imgObj = imgObj;
                containerTween = new Tween(containerMC, "alpha", Regular.easeIn, 1, 0, 0.5, true);
                           containerTween.addEventListener(TweenEvent.MOTION_FINISH, fadeOutFinished);
            } else {
                //nothing to fade out, proceed to initiate
                initiateImageOpen(imgObj);
            }
        }

        public static function fadeOutFinished (e:TweenEvent) {
            Gallery.initiateImageOpen(imgObj);
        }

//this is called next, (or first, if you change gallery in menu this function starts working on first image inside gallery to auto-open first image)
        public static function initiateImageOpen(imgObj:Object)
        {
            if(timeline.contains(containerMC))
            {
                Gallery.imgObj = imgObj;
                currentImageNum = imgObj.number;
                imageLoader = new Loader();    //public static loader
                attachPreloader(imgObj);  //this function attaches preloader MC and textbox, and I swear it is called only this once
                imageLoader.load(new URLRequest(imgObj.path));
                imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
                imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preloaderProgress);
            } else {
                timeline.debug.text = "no containerMC";
            }
        }

                //looks a bit messy because of all the comments, those are remnants from previous versions and attempts
        public static function attachPreloader(imgObj:Object)
        {
            timeline.debug.text += "
ATTACH PRELOADER 
"; //this is why I'm sure its called only once per thumb clicked!
            //preloaderText = new TextField();
            try {
            preloaderMC = new PreloaderItem(); //PreloadItem is MovieClip from library
            timeline.addChild(preloaderMC);
            preloaderMC.x = (Data.stageWidth/2) - (preloaderMC.width/2);
            preloaderMC.y = (Data.stageHeight/2) - (preloaderMC.height / 2);
            //preloaderMC.addChild(preloaderText);
            } catch(error:Error) {
                timeline.debug.text = "attachPreloader error " + error;
            }
            preloaderText = preloaderMC.preloaderText;
            
            preloaderFormat = new TextFormat();
            preloaderFormat.size = 30;
            preloaderFormat.color = 0xFFFFFF;
            preloaderText.setTextFormat(preloaderFormat);
            
        }

//this is function which instead of changing text inside textfield, just writes new text over the old one, making both visible. It seems like it doesn't do this on every update, maybe each third time it gets called, but in the end, by the time it count to 100, I have like 5 to 10 text fields all visible and all writen one over another
        public static function preloaderProgress (e:ProgressEvent) {
                try {
                    var percent:Number = Math.floor((e.bytesLoaded / Gallery.imgObj.size) * 100);
                    //TextField(preloaderMC.getChildByName("preloaderPreloaderText")).text = "";    //ocajan pokusaj
                    //TextField(preloaderMC.getChildByName("preloaderPreloaderText")).text = String(percent);
                    //preloaderText.text = String(percent);
                    //preloaderText.setTextFormat(preloaderFormat);
                    preloaderMC.preloaderText.text = String(percent);  //this writes text which overlaps old one, in most cases
                    preloaderMC.preloaderText.setTextFormat(preloaderFormat);
                } catch(error:Error) {
                    timeline.debug.text = "preloaderProgress error " + error;
                }
        }

public static function imageLoaded(e:Event) 
        {
            //TextField(preloaderMC.getChildByName("preloaderPreloaderText")).text = "LOADED";
            //TextField(preloaderMC.getChildByName("preloaderPreloaderText")).setTextFormat(preloaderFormat);
            //preloaderMC.removeChild(preloaderText);
            try {
                if(timeline.contains(preloaderMC)) {
                    MovieClip(preloaderMC.parent).removeChild(preloaderMC);
                } else {
                    timeline.debug.text += "
no preloaderMC
";
                                   //this sometimes gives error 1009
                }
 . . . and blah blah the rest of function and code.... 

I’m sorry I didn’t put the rest of code and entire class, but it would be too big and I’m sure there is no problem in rest of code…

Please help.