开发者

Error 1009 cannot access a property----again

Hello I'm stuck on this one which is trying to show a game level on the game and getting an output error 1009. I'm doing something wrong but can't figure. Here is the code:

                                    if ( levelNumber ==1) {
                    var level:Number = 1;
                    showLevel.text=level.toString();
                    showLevel.text = String ("Level:     " +level);


                if ( levelNumber ==2) {
                    var level:Number = 2;
                    showLevel.text=level.toString();
                    showLevel.text = String("Level:     " +level);
                    var numBombs:Number = 4;

                }else if( levelNumber ==3 ) {
                    var level:Number = 3;
                    showLevel.text=level.toString();
                    showLevel.text = String ("Level:     " +level);

The debugger says it's the line with showLevel.text=level.toString(); whic开发者_JAVA百科h I have set as a Number ie private var level:Number =0. I hope this is sufficient code to let you know what's going on here. It's also coming up with a duplicate variable definition - compiler error on var level:Number =2 and the next one that =3.Thanking you in advance for any assistance. Cheers.


Error #1009 is indeed a null reference error. I see your level is declared and has a right value. Maybe the point is that your showLevel object (I guess it's a label) is not declared yet.

The problem can be that you use:

private var showLevel:mx.controls.Label;

instead of:

private var showLevel:mx.controls.Label = new mx.controls.Label();

otherwise if you make your showLevel in a viewStack you must be sure that your content is created yet. Therefor you can use:

<mx:ViewStack id="yourView" creationPolicy="all">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜