Ferenc Dajka
Ferenc Dajka

Reputation: 1051

Dynamic text unable to be changed

I made a preloading screen in flash, I have a preloader MovieClip wich contains the progressBar and a progressText MC-s both are created by me, in the preLoader class I use the code like this:

... ldrInf.addEventListener(ProgressEvent.PROGRESS, onProgress); ...

private function onProgress(e:ProgressEvent):void {
        var percent:Number = e.bytesLoaded / e.bytesTotal;
        progressBar.scaleX = percent;           
        progressText.text = Math.floor(percent * 100).toString() + "%";
    }

The scaling works well, but the text is not changing, I set "Automatically declare stage instances" on, and I have an error like that (i dont know it has to do something with my problem, but anyways): ReferenceError: Error #1065: Variable Font1 is not defined.

And if i create a class for the ProgressText MC, than I get an error: 1119: Access of possibly undefined property text through a reference with static type ProgressText. I know it is becouse, well I don't have text property in my class, but the text variable is some kind of built in variable for the textfields I suppose so I may not have to define it I think.

Please help

Upvotes: 0

Views: 133

Answers (1)

net.uk.sweet
net.uk.sweet

Reputation: 12431

It sounds to me like you're trying unsuccessfully to embed a font. It would be useful if you could post the code where you set the TextFormat of your TextField instance, though you could try setting the font directly to "Arial" or commenting out that line completely to rule it out as the cause of the problem.

If you want to create a custom class for your TextField (though it's not clear whether that's altogether necessary in this instance) you would need to either extend the TextField class in your custom class (in which case it will inherit the TextField.text property) or implement a setter of your own to set the text on a TextField instance stored as a property of the class.

Extend TextField (inheritance) example:

package 
{
    import flash.text.TextField;

    public class CustomTextField extends TextField
    {
        public function CustomTextField()
        {

        }

        override public function set text(value:String):void
        {
            // could do custom stuff here or omit override altogether if it isn't required
            value = "custom " + value;

            super.text = value;
        }
    }
}  

TextField property (composition) example:

package 
{
    import flash.text.TextField;

    public class CustomTextField extends Sprite
    {
        private var textField:TextField = new TextField();

        public function CustomTextField()
        {
            this.addChild(textField);
        }

        public function setText(value:String):void
        {
            textField.text = value;
        }
    }
}

Upvotes: 1

Related Questions