Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

1119: Access of possibly undefined property text through a reference with static type Class.

Community Beginner ,
Jan 25, 2011 Jan 25, 2011


package{
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.Sprite;
   
    public class timer2 extends Sprite {
        public function timer2() {
           
              var count:Number = 60;
              var myTimer:Timer = new Timer(1000,count);


            myTimer.addEventListener(TimerEvent.TIMER, countdown);
            myTimer.start();
       
           

            function countdown(event:TimerEvent):void {
            myTimer2.text = String((count)-myTimer.currentCount);
            }
           
}
}
}

i am creating a timer and i have a error can somebody help me with this|???tnx in advance?

TOPICS
ActionScript
5.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 26, 2011 Jan 26, 2011

You need to import the class, ie:

import flash.text.TextFormat;
Translate
Community Expert ,
Jan 26, 2011 Jan 26, 2011

myTimer2.text

"myTimer2" is not defined in anywhere?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2011 Jan 26, 2011

yes i also noticed it earlier but when i changed it to this codes


package{
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.Sprite;
    import flash.text.TextField;
   
    public class timer2 extends Sprite {
       
       
        public function timer2() {
           
              var count:Number = 60;
              var myTimer:Timer = new Timer(1000,count);
              var Timer2 : TextField = new myTimer2();

            function countdown(event:TimerEvent):void {
            Timer2.text = String((count)-myTimer.currentCount);
            myTimer.addEventListener(TimerEvent.TIMER, countdown);
                        myTimer.start();
            }
           
}
}
}

it says 1067: Implicit coercion of a value of type myTimer2 to an unrelated type flash.text:TextField.

what is the problem here?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2011 Jan 26, 2011

var Timer2 : TextField = new myTimer2();

For this to work "myTimer2" needs to be a class extending TextField, but it does not appear to be.

Shall I give you an example of how to display a countdown in a Sprite?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2011 Jan 26, 2011

sure tnx in advance!

it should be in package also huh..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2011 Jan 26, 2011
package {
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.utils.Timer;
   
    public class Countdown extends Sprite {
        private var textfield:TextField;
       
        public function Countdown():void {
            var count:uint = 60;
            var myTimer:Timer = new Timer(1000, count);
            myTimer.addEventListener(TimerEvent.TIMER, countdown, false, 0, true);
            myTimer.start();
            textfield = new TextField();
            textfield.text = String(count);
            addChild(textfield);
        }
       
        private function countdown(e:TimerEvent):void {
            textfield.text = String(parseInt(textfield.text) - 1);
        }
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2011 Jan 26, 2011

tnx but how can i change the font style, font size and location of the text????tnx agen

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2011 Jan 26, 2011

To change the font style/size you can either use StyleSheet or TextFormat but the latter would be easier for this example. Just do something like:

textfield.defaultTextFormat = new TextFormat("Baghdad", 24, 0xff0000, true);

(NB. you need to embed fonts if you want to use non-device fonts.)

To set the position of the TextField just do:

textfield.x = 30;
textfield.y = 60;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2011 Jan 26, 2011

where will i put the

textfield.defaultTextFormat = new TextFormat("Baghdad", 24, 0xff0000, true)

sorry im so dumb..

because i put it this way..

package {
    import flash.display.MovieClip;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.utils.Timer;
   
    public class timer2 extends MovieClip {
        private var textfield:TextField;
       
        public function timer2():void {
            var count:uint = 60;
            var myTimer:Timer = new Timer(1000, count);
            myTimer.addEventListener(TimerEvent.TIMER, countdown, false, 0, true);
            myTimer.start();
            textfield = new TextField();
            textfield.defaultTextFormat = new TextFormat("Arial", 24, 0xff0000, true);
            textfield.x = 30;
            textfield.y = 60;
            textfield.text = String(count);

            addChild(textfield);
        }
       
        private function countdown(e:TimerEvent):void {
            textfield.text = String(parseInt(textfield.text) - 1);
        }
    }
}

and the error is this

1180: Call to a possibly undefined method TextFormat.

tnx again..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2011 Jan 26, 2011

You need to import the class, ie:

import flash.text.TextFormat;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2011 Jan 26, 2011
LATEST

Thank u so much i trully helped...

and it works

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines