Why have error "Access of undefined property"?


in class have error 2 variables myformat , abouttext. can't understand why? there import line, , class in own file. before error text of class in main.as , working fine. when tried move code in different class error ocures.

 

package 
{
     import flash.display.sprite;
     import flash.events.event;
     import flash.display.*;
     import flash.events.mouseevent;
     import flash.system.fscommand;
     import flash.text.*;

     public class menuscreen extends sprite
     {
          var myformat:textformat = new textformat();     
          var abouttext:textfield = new textfield();

          var btn_play:mybuttonclass = new mybuttonclass();
          var btn_opt:mybuttonclass = new mybuttonclass();
          var btn_inst:mybuttonclass = new mybuttonclass();
          var btn_abt:mybuttonclass = new mybuttonclass();
          var btn_ext:mybuttonclass = new mybuttonclass();


          myformat.font = "times new roman";
          myformat.size = 20;
           myformat.color = 0x000000;                    

          abouttext.width = 550;
          abouttext.height = 250;
          abouttext.x = 225;
          abouttext.y = 80;
          abouttext.selectable = false;
          abouttext.settextformat(myformat);
          addchild(abouttext);

          public function menuscreen()
                    {
                    super();


                         btn_play.name = "btn_play";
                         btn_play.label = "play";
                         btn_play.addeventlistener(mouseevent.click, btnmousehandle);
                         addchild(btn_play).y = 50;
                         btn_play.x = 80


                         btn_opt.name = "btn_options";
                         btn_opt.label = "options"
                         btn_opt.addeventlistener(mouseevent.click, btnmousehandle);
                         addchild(btn_opt).y = 100;
                         btn_opt.x = 80


                         btn_inst.name = "btn_instructions";
                         btn_inst.label = "instructions"
                         btn_inst.addeventlistener(mouseevent.click, btnmousehandle);
                         addchild(btn_inst).y = 150;
                         btn_inst.x = 80


                         btn_abt.name = "btn_about";
                         btn_abt.label = "about"
                         btn_abt.addeventlistener(mouseevent.click, btnmousehandle);
                         addchild(btn_abt).y = 200;
                         btn_abt.x = 80


                         btn_ext.name = "btn_exit";
                         btn_ext.label = "exit"
                         btn_ext.addeventlistener(mouseevent.click, btnmousehandle);
                         addchild(btn_ext).y = 250;
                         btn_ext.x = 80
                    }

          function btnmousehandle(e:mouseevent):void
                    {                         
                         switch(e.target.name){
                              case "btn_play":
                                   var testswc:movieclip = new wsymbol_mc;
                                   trace("btn_01 click");
                                   testswc.x = 50;
                                   testswc.y = 50;
                                   addchild(testswc);
                                   break;
                              case "btn_options":
                                   trace("btn_02 click");
                                   break;
                              case "btn_instructions":
                                   trace("btn_03 click");
                                   showtextblock (e.target.name);
                                   break;
                              case "btn_about":
                                   trace("btn_04 click");
                                   showtextblock (e.target.name);
                                   break;
                              case "btn_exit":
                                   trace("btn_05 click");
                                   fscommand('quit');
                                   break;
                         }
                    }

          function showtextblock (strid:string):void
                    {          
                         if (strid == "btn_instructions")
                              {
                                   trace("ins");
                                   abouttext.text = "some text here";
                              }
                         else
                              {
                                   trace("ab");
                                   myformat.align = textformatalign.center;
                                   myformat.leading = 10;
                                   abouttext.defaulttextformat = myformat;
                                   abouttext.text = "some text here";
                              }
                    }

     }

}

this main.as:

 

package
{
     import flash.display.sprite;
     import flash.events.event;
     import flash.display.*;
     import flash.events.mouseevent;
     import flash.system.fscommand;
     import flash.text.*;

     public class main extends sprite
     {

          var mscreen:menuscreen = new menuscreen;



          public function main():void
          {
               if (stage) init();
               else addeventlistener(event.added_to_stage, init);
          }

          private function init(e:event = null):void
          {
               removeeventlistener(event.added_to_stage, init);
               addchild(mscreen);


          }

     }

}

one man told me reason in many actions outside functions, true? restriction in as3?

try moving variable declarations inside first function.  make variables private/public needed.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Soustraire une selection

After Effects: could not find dvaeve_dialogs.txt

Illustrator cs6 "Invalid Serial Number"