samedi 30 mai 2015

Can't change text of movieclip in class from script in flash file

I have a class with a movieclip, in movie clip have a dynamic text named txt: When I change text for txt I see "error Cannot access a property or method of a null object reference."

package  {
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.text.TextLineMetrics;
    import flash.display.MovieClip;
    import flash.ui.Keyboard;
    import flash.events.MouseEvent;

    public class iKeyboard {
        public var akey:MovieClip; 
        public function iKeyboard() {   
            akey = new key();
        }
        public function SetText(s:String)
        {
            txt.text = s;
        }       
    }

In script in flash file:

var ak:iKeyboard;
function Fuc1()
{
    ak:iKeyboard = new iKeyboard();
    ak.txt.text = "A"// => OK
    ak.SetText("B")// => fail error: Cannot access a property or method of a null object reference.
}

function Fuc2()
{
    ak.txt.text = "A"// fail error: Cannot access a property or method of a null object reference.
    ak.SetText("B")// => fail error: Cannot access a property or method of a null object reference.
}

Please help me resolve that !

Aucun commentaire:

Enregistrer un commentaire