7 Replies Latest reply: Aug 21, 2011 1:36 AM by StoneChameleon RSS

    Error 1069 Property 0 not found on flash.text.TextField and there is no default value

    StoneChameleon Community Member

      So, I've been working on this for a few days and what drives me nuts is this is a simple file with a lot of simple script and I still can't figure out what this error is and how to fix it: Property 0 not found on flash.text.TextField and there is no default value

       

      The script below what we're looking at, everything is drawn with AS3, there are no library objects (save for the font). I sort of understand what the error is saying, but I don't fully understand it or how to fix it.

       

       

      import flash.display.MovieClip;
      import flash.events.MouseEvent;
      import flash.events.Event;
      import flash.filters.BlurFilter;
      import flash.display.Shape;
      
      import flash.display.Sprite;
      import flash.display.Graphics;
      import flash.events.*;
      import flash.geom.*;
      import flash.events.*;
      
      var boxBg:Shape = new Shape();
          
      boxBg.graphics.lineStyle(1, 0x000000, .5, true);
      boxBg.graphics.beginFill(0xff6600);
      boxBg.graphics.drawRect(0, 0, 50, 50);
      boxBg.graphics.endFill();
      
      var box:Sprite = new Sprite();
      box.x = 335;
      box.y = 245;
      
      addChild(box);
      box.addChild(boxBg);
      
      var toggleBg:Shape = new Shape();
      var toggleBtn:Sprite = new Sprite();
          
      toggleBg.graphics.lineStyle(1, 0xefefef, .5, true);
      toggleBg.graphics.beginFill(0xffffff);
      toggleBg.graphics.drawCircle(0, 0, 25);
      toggleBg.graphics.endFill();
      toggleBtn.buttonMode = true;
      toggleBtn.mouseChildren = false;
      
      toggleBtn.x = stage.stageWidth - 75;
      toggleBtn.y = 25;
      
      addChild(toggleBtn);
      toggleBtn.addChild(toggleBg);
      
      for (var i:int = 0; i < 10; i++) {
          var btnBg:Shape = new Shape();
          
          btnBg.graphics.lineStyle(1, 0xefefef, .5, true);
          btnBg.graphics.beginFill(0xffffff);
          btnBg.graphics.moveTo(12, 0);
          btnBg.graphics.lineTo(24, 20);
          btnBg.graphics.lineTo(0, 20);
          btnBg.graphics.lineTo(12,0);
          btnBg.graphics.endFill();
          
          var btnFont = new Myriad();
          
          var btnFormat:TextFormat = new TextFormat();
          btnFormat.font = btnFont.fontName;
          btnFormat.size = 12;
          btnFormat.align = "center";
          btnFormat.color = 0xffffff;
          
          var btnTxt:TextField = new TextField();
          btnTxt.defaultTextFormat = btnFormat;
          btnTxt.width = 50;
          btnTxt.height = 20;
          btnTxt.y = 5;
          
          var myBtn:Sprite = new Sprite();
          
          myBtn.name = ("Blend " + (i + 1));
          myBtn.buttonMode = true;
          myBtn.mouseChildren = false;
          
          addChild(myBtn);
          
          myBtn.x = 10 + (i * 75);
          myBtn.y = 500;
          
          myBtn.addChild(btnBg);
          myBtn.addChild(btnTxt);
          
          btnTxt.text = myBtn.name;
          
          myBtn.addEventListener(MouseEvent.CLICK, btnHandler);
          myBtn.addEventListener(MouseEvent.ROLL_OVER, btnHandler);
          myBtn.addEventListener(MouseEvent.ROLL_OUT, btnHandler);
          toggleBtn.addEventListener(MouseEvent.MOUSE_DOWN, onToggleVisible);
      }
      
      function btnHandler(event:MouseEvent):void {
          if(event.type == MouseEvent.CLICK){
              if(event.currentTarget == btnTxt[0]){
                  box.blendMode = BlendMode.NORMAL;
              }
              
              if(event.currentTarget == btnTxt[1]){
                  box.blendMode = BlendMode.DARKEN;
              }
              
              if(event.currentTarget == btnTxt[2]){
                  box.blendMode = BlendMode.DIFFERENCE;
              }
              if(event.currentTarget == btnTxt[3]){
                  box.blendMode = BlendMode.HARDLIGHT;
              }
              
              if(event.currentTarget == btnTxt[4]){
                  box.blendMode = BlendMode.INVERT;
              }
              
              if(event.currentTarget == btnTxt[5]){
                  box.blendMode = BlendMode.LIGHTEN;
              }
              
              if(event.currentTarget == btnTxt[6]){
                  box.blendMode = BlendMode.MULTIPLY;
              }
              
              if(event.currentTarget == btnTxt[7]){
                  box.blendMode = BlendMode.OVERLAY;
              }
              
              if(event.currentTarget == btnTxt[8]){
                  box.blendMode = BlendMode.SCREEN;
              }
              
              if(event.currentTarget == btnTxt[9]){
                  box.blendMode = BlendMode.SUBTRACT;
              }
          }
      }
          
      function onToggleVisible(event:MouseEvent):void {
          box.visible = !box.visible;
      }
      

       

      I've searched through similar problems, but couldn't find a proper solution. If anyone can help me pinpoint the issue and solution, I would be incredibly grateful.

        • 1. Re: Error 1069 Property 0 not found on flash.text.TextField and there is no default value
          Andrei1 Community Member

          The statements like this

           

          event.currentTarget == btnTxt[0]

           

          make no sense.

           

          1. currentTarget is a button - myBtn in the loop

          2. btnTxt is a TextField - not an Array, so there is no btnTxt[0] or 1, 2, 3, etc. for that matter.

          • 2. Re: Error 1069 Property 0 not found on flash.text.TextField and there is no default value
            Andrei1 Community Member

            And this statement in the loop has no sense as well:

             

            event.currentTarget == btnTxt[0]

            • 3. Re: Error 1069 Property 0 not found on flash.text.TextField and there is no default value
              Andrei1 Community Member

              The following code makes more sense, it is more efficient (although it can be more efficient) and it is better organized:

               

              import flash.display.Shape;
              import flash.display.Sprite;
              import flash.events.*;
              import flash.geom.*;
              import flash.events.*;
              import flash.text.*;
              
              var box:Sprite;
              var toggleBtn:Sprite;
              var btnFont:Font;
              var btnFormat:TextFormat;
              
              init();
              
              function init():void
              {
                   initFormat();
                   makeBox();
                   makeToggleButton();
                   makeButtons();
              }
              
              function initFormat():void
              {
                   btnFont = new Myriad();
                   btnFormat = new TextFormat();
                   btnFormat.font = btnFont.fontName;
                   btnFormat.size = 12;
                   btnFormat.align = "center";
                   btnFormat.color = 0xffffff;
              }
              
              function makeToggleButton():void
              {
                   toggleBtn = new Sprite();
                   toggleBtn.graphics.lineStyle(1, 0xefefef, .5, true);
                   toggleBtn.graphics.beginFill(0xffffff);
                   toggleBtn.graphics.drawCircle(0, 0, 25);
                   toggleBtn.graphics.endFill();
                   toggleBtn.buttonMode = true;
                   toggleBtn.mouseChildren = false;
                   toggleBtn.addEventListener(MouseEvent.MOUSE_DOWN, onToggleVisible);
                   addChild(toggleBtn);
                   
                   toggleBtn.x = stage.stageWidth - 75;
                   toggleBtn.y = 25;
              }
              
              function makeBox():void
              {
                   box = new Sprite();
                   box.graphics.lineStyle(1, 0x000000, .5, true);
                   box.graphics.beginFill(0xff6600);
                   box.graphics.drawRect(0, 0, 50, 50);
                   box.graphics.endFill();
                   
                   addChild(box);
                   
                   box.x = 335;
                   box.y = 245;
              }
              
              function makeButtons():void
              {
                   var myBtn:Sprite;
                   for (var i:int = 0; i < 10; i++)
                   {
                        myBtn = drawButton("Blend " + (i + 1));
                        addChild(myBtn);
                        myBtn.x = 10 + i * 75;
                        myBtn.y = 500;
                        myBtn.addEventListener(MouseEvent.CLICK, btnHandler);
                        myBtn.addEventListener(MouseEvent.ROLL_OVER, btnHandler);
                        myBtn.addEventListener(MouseEvent.ROLL_OUT, btnHandler);
                   }
              }
              
              function btnHandler(e:MouseEvent):void
              {
                   if (e.type == MouseEvent.CLICK)
                   {
                        switch (e.currentTarget.name)
                        {
                             case "Blend 1": 
                                  box.blendMode = BlendMode.NORMAL;
                                  break;
                             case "Blend 2": 
                                  box.blendMode = BlendMode.DARKEN;
                                  break;
                             case "Blend 3": 
                                  box.blendMode = BlendMode.DIFFERENCE;
                                  break;
                             case "Blend 4": 
                                  box.blendMode = BlendMode.HARDLIGHT;
                                  break;
                             case "Blend 5": 
                                  box.blendMode = BlendMode.INVERT;
                                  break;
                             case "Blend 6": 
                                  box.blendMode = BlendMode.LIGHTEN;
                                  break;
                             case "Blend 7": 
                                  box.blendMode = BlendMode.MULTIPLY;
                                  break;
                             case "Blend 8": 
                                  box.blendMode = BlendMode.OVERLAY;
                                  break;
                             case "Blend 9": 
                                  box.blendMode = BlendMode.SCREEN;
                                  break;
                             case "Blend 10": 
                                  box.blendMode = BlendMode.SUBTRACT;
                                  break;
                        }
                   }
              }
              
              function onToggleVisible(e:MouseEvent):void
              {
                   box.visible = !box.visible;
              }
              
              function drawButton(buttonName:String):Sprite
              {
                   var btnTxt:TextField = new TextField();
                   btnTxt.defaultTextFormat = btnFormat;
                   btnTxt.width = 50;
                   btnTxt.height = 20;
                   btnTxt.y = 5;
                   btnTxt.text = buttonName;
                   
                   var myBtn:Sprite = new Sprite();
                   myBtn.graphics.lineStyle(1, 0xefefef, .5, true);
                   myBtn.graphics.beginFill(0xffffff);
                   myBtn.graphics.moveTo(12, 0);
                   myBtn.graphics.lineTo(24, 20);
                   myBtn.graphics.lineTo(0, 20);
                   myBtn.graphics.lineTo(12, 0);
                   myBtn.graphics.endFill();
                   
                   myBtn.name = buttonName;
                   myBtn.buttonMode = true;
                   myBtn.mouseChildren = false;
                   
                   myBtn.addChild(btnBg);
                   myBtn.addChild(btnTxt);
                   
                   return myBtn;
              }
              
              • 4. Re: Error 1069 Property 0 not found on flash.text.TextField and there is no default value
                StoneChameleon Community Member

                Andrei,

                 

                You are awesome. Thank you so much.

                 

                I had it all backwards in my head and even though I knew it wasn't an array, I continued thinking I still had to access the index of myBtn.

                 

                Again, thank you so much and for the bonus code organization, it is more effecient. I wrote the stuff and I was actually just trying to put it into order, but yours is much better than what I have thus far.

                • 5. Re: Error 1069 Property 0 not found on flash.text.TextField and there is no default value
                  Andrei1 Community Member

                  You are welcome.

                   

                  Here is a couple or further improvements:

                   

                  1. The code below introduces blends array and buttons became MovieClips.

                   

                  Although conditionals are great language features, one should always try to avoid them. With this code you don;t need conditional in figuring what blends to use. Because buttons are MovieClips - they can be assigned dynamic properties - in this case property index. So, in the function btnHandler lends are linked via index - thus no conditionals.

                   

                  2. btnHandler has switch for rerouting functionality based on Event type. switch statement is more efficient than if...else because values are indexed by compiler. This, in cases when values are predefined (not calculated) switches are preferable.

                   

                  import flash.display.*;
                  import flash.events.*;
                  import flash.geom.*;
                  import flash.events.*;
                  import flash.text.*;
                  
                  var box:Sprite;
                  var toggleBtn:Sprite;
                  var btnFont:Font;
                  var btnFormat:TextFormat;
                  var blends:Array = [BlendMode.NORMAL, BlendMode.DARKEN, BlendMode.DIFFERENCE, BlendMode.HARDLIGHT, BlendMode.INVERT, BlendMode.LIGHTEN, BlendMode.MULTIPLY, BlendMode.OVERLAY, BlendMode.SCREEN, BlendMode.SUBTRACT];
                  
                  init();
                  
                  function init():void
                  {
                       initFormat();
                       makeBox();
                       makeToggleButton();
                       makeButtons();
                  }
                  
                  function initFormat():void
                  {
                       btnFont = new Myriad();
                       btnFormat = new TextFormat();
                       btnFormat.font = btnFont.fontName;
                       btnFormat.size = 12;
                       btnFormat.align = "center";
                       btnFormat.color = 0xffffff;
                  }
                  
                  function makeToggleButton():void
                  {
                       toggleBtn = new Sprite();
                       toggleBtn.graphics.lineStyle(1, 0xefefef, .5, true);
                       toggleBtn.graphics.beginFill(0xffffff);
                       toggleBtn.graphics.drawCircle(0, 0, 25);
                       toggleBtn.graphics.endFill();
                       toggleBtn.buttonMode = true;
                       toggleBtn.mouseChildren = false;
                       toggleBtn.addEventListener(MouseEvent.MOUSE_DOWN, onToggleVisible);
                       addChild(toggleBtn);
                       
                       toggleBtn.x = stage.stageWidth - 75;
                       toggleBtn.y = 25;
                  }
                  
                  function makeBox():void
                  {
                       box = new Sprite();
                       box.graphics.lineStyle(1, 0x000000, .5, true);
                       box.graphics.beginFill(0xff6600);
                       box.graphics.drawRect(0, 0, 50, 50);
                       box.graphics.endFill();
                       
                       addChild(box);
                       
                       box.x = 335;
                       box.y = 245;
                  }
                  
                  function makeButtons():void
                  {
                       var myBtn:MovieClip;
                       for (var i:int = 0; i < 10; i++)
                       {
                            myBtn = drawButton("Blend " + (i + 1));
                            // index is introduced
                            myBtn.index = i;
                            addChild(myBtn);
                            myBtn.x = 10 + i * 75;
                            myBtn.y = 500;
                            myBtn.addEventListener(MouseEvent.CLICK, btnHandler);
                            myBtn.addEventListener(MouseEvent.ROLL_OVER, btnHandler);
                            myBtn.addEventListener(MouseEvent.ROLL_OUT, btnHandler);
                       }
                  }
                  
                  function btnHandler(e:MouseEvent):void
                  {
                       switch(e.type) {
                            case MouseEvent.CLICK:
                                 box.blendMode = blends[MovieClip(e.currentTarget).index];
                                 break;
                                 
                            case MouseEvent.ROLL_OVER:
                                 
                                 break;
                                 
                            case MouseEvent.ROLL_OUT:
                                 
                                 break;
                       }
                  }
                  
                  function onToggleVisible(e:MouseEvent):void
                  {
                       box.visible = !box.visible;
                  }
                  
                  function drawButton(buttonName:String):MovieClip
                  {
                       var btnTxt:TextField = new TextField();
                       btnTxt.defaultTextFormat = btnFormat;
                       btnTxt.width = 50;
                       btnTxt.height = 20;
                       btnTxt.y = 5;
                       btnTxt.text = buttonName;
                       
                       var myBtn:MovieClip = new MovieClip();
                       myBtn.graphics.lineStyle(1, 0xefefef, .5, true);
                       myBtn.graphics.beginFill(0xffffff);
                       myBtn.graphics.moveTo(12, 0);
                       myBtn.graphics.lineTo(24, 20);
                       myBtn.graphics.lineTo(0, 20);
                       myBtn.graphics.lineTo(12, 0);
                       myBtn.graphics.endFill();
                       
                       myBtn.name = buttonName;
                       myBtn.buttonMode = true;
                       myBtn.mouseChildren = false;
                       
                       myBtn.addChild(btnBg);
                       myBtn.addChild(btnTxt);
                       
                       return myBtn;
                  }
                  
                  
                  • 6. Re: Error 1069 Property 0 not found on flash.text.TextField and there is no default value
                    Andrei1 Community Member

                    And another possibility that come with the introduction of bleeds array. The buttons can now be more descriptive - include blends names. Changes are just on makeButtons function. Also note that buttons x position depends on previous width.

                     

                    function makeButtons():void
                    {
                         var myBtn:MovieClip;
                         var gap:Number = 10;
                         var nextX:Number = gap;
                         for (var i:int = 0; i < 10; i++)
                         {
                              myBtn = drawButton("Blend " + blends[i]);
                              // index is introduced
                              myBtn.index = i;
                              addChild(myBtn);
                              myBtn.x = nextX;
                              myBtn.y = 500;
                              myBtn.addEventListener(MouseEvent.CLICK, btnHandler);
                              myBtn.addEventListener(MouseEvent.ROLL_OVER, btnHandler);
                              myBtn.addEventListener(MouseEvent.ROLL_OUT, btnHandler);
                              // adjust nextX base on current button width
                              nextX += myBtn.width + gap;
                         }
                    }