TypeError:错误#2007:

时间:2015-01-12 14:53:49

标签: actionscript-3 flex

我收到此运行时错误 -

TypeError: Error #2007: パラメーター text は null 以外でなければなりません。

参数text必须为非null         在flash.text :: TextField / set text()         在Tile / refresh()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Tile.as:68]         在Tile / init()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Tile.as:58]         在flash.display :: DisplayObjectContainer / addChild()         在Main / tileform()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:115]         在Main / deal()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:106]         在Main / creattile()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:86]         在Main / init()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:54]         在Main()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:33]

我不能完全相同的问题。

我认为此代码是问题的根源,但如何解决?

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.events.*;
    import excludespace;
    import Math;
    import flash.display.Bitmap;
    import background;
    import returncarrier;
    import tilecarrier;
    import Array;
    import flash.text.*

    public class Tile extends Sprite {
        internal var mode :String = "practice";
        internal var submode :String = "blank";
        private var setX:int;
        private var setY:int;
        private var IDlocal:int;
        private var kanalocal:String;
        private var valuelocal:int;
        private var kanafield:TextField;
        private var valuefield:TextField;
        internal var wordmultiplier:Array= new Array([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,3,0,0,0,0,0,0,3,0,0,0,0,0,0,3],[0,0,2,0,0,0,0,0,0,0,0,0,0,0,2,0],[0,0,0,2,0,0,0,0,0,0,0,0,0,2,0,0],[0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0],[0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0], [0,0,0,0,0,0,0,0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1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1]]) ;

        /*[Embed(source="/../lib/meiryo",
        fontName = "myFont",
        mimeType = "application/x-font",
        advancedAntiAliasing="true",
        embedAsCFF = "false")]
        internal var japanese:Class;*/
        [Embed(source="/../lib/blank.png")]
        internal var blank1:Class;

        internal var checkstart:Boolean = false;
        internal var start:Boolean = true;
        private var blank2:Bitmap;

        public function Tile(ID:int,kana:String,value:int):void {
            IDlocal = ID;
            kanalocal = kana;
            valuelocal = value;
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event= null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            blank2 = new blank1();
            this.addChild(blank2);
            addEventListener(excludespace.EVENT_START,refresh)
        }

        private function refresh(e:excludespace):void {
            var myFormat:TextFormat = new TextFormat();
            myFormat.size = 5;
            myFormat.align = TextFormatAlign.CENTER;
            //myFormat.font = myFont2.fontName;

            var myText:TextField = new TextField();
            myText.defaultTextFormat = myFormat;
            myText.embedFonts = true;
            myText.antiAliasType = AntiAliasType.ADVANCED;
            myText.text = kanalocal;
            addChild(myText);
            myText.width = 15;
            myText.height = 15;
            myText.x = 0;
            myText.y = 0;
        }
    }
}

在Main.as

Tileform甚至不应该运行,但它仍然提供输出。 现在我得到TypeError:错误#1034:强制型変换に失败しました.flashscreen_flash @ 44bbba1をflash.display.Spriteに変换できません。 我没有强迫。 flashscreen_flash @ 44bbba1无法转换为flash.display.Sprite。     在flashscreen / init()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ flashscreen.as:23]     在flash.display :: DisplayObjectContainer / addChild()     在Main / tileform()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:153]     在Main / deal()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:122]     在Main / creattile()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:101]     在Main / init()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:69]     在Main()[C:\ Users \ Makiko \ Desktop \ Michael \ Games \ New Project \ src \ Main.as:33]

                private function deal():void
        {

            trace(hand_current.length);

            for (var i:int = 0; i < (7-hand_current.length); i++)
            {

            var letterchoice:Number;
            var randomnum:Number;
            randomnum = (Math.random() * (1 + pool.length));
            trace (randomnum);
            letterchoice = Math.floor(randomnum);
            trace (letterchoice);
            hand_current.push(pool[letterchoice]);
            pool.splice(letterchoice, 1);

            for (var k:int = 0; k < 6; k++)
                {
                    trace(k);
                    trace(baseset[hand_current[k]]);
                    trace(basevalue[hand_current[k]] );}
            }
            }

            internal var tilearray:Array = new Array();


            private function tileform():void

            {
for (var i:int = 0; i < 6; i++)
                {var atile:Sprite = new Tile(i,baseset[hand_current[i]],basevalue[hand_current[i]] );

                atile.x = (i * 32);
             atile.y = 480;
             addChild(atile);
             tilearray.push(atile);
                }
             screen = new flashscreen();
             screen.x = 0;
             screen.y = 0;
             addChild(screen);

            }

1 个答案:

答案 0 :(得分:2)

当需要非null值时,尝试将属性设置为空值时,将发生错误2007。我相信kanalocal是空值。

myText.text = kanalocal;