0

我是刚开始学习actionscript 3,下面是我的代码,当我启动代码时,它仍然在第36帧报告错误,但没有找到错误在哪一行。请帮我调试它们...... TypeError:错误#1009:无法访问空对象引用的属性或方法。在 flashmo_217_v_shape_fla::MainTimeline/frame36()

以下是frame36中的代码

stop();
fm_button.visible = false;


import caurina.transitions.*;

var menu_label_North:Array = new Array("Animals Collection", 
                                                                                 "Flowers Collection",
                                                                                 "Leaves Collection",
                                                                                 "Mixed Collection",
                                                                                 "Extra Collection",
                                                                                 "Special Awards",
                                                                                 "Company Background",
                                                                                 "Contact Information");


var total_north:Number = menu_label_North.length;
var i_north:Number = 0;
var page_north:Number;
var main_menu_North:MovieClip = new MovieClip();
stage.addChild(main_menu_North);


for (i_north = 0; i_north < total_north; i_north++)
{
          var btn_north = new flashmo_button();
          btn_north.name = "btn" + i_north;
          btn_north.x = fm_button.x + i_north * ( fm_button.width + 12 );
          btn_north.y = fm_button.y;
          btn_north.buttonMode = true;
          btn_north.item_no = i_north;
          btn_north.flashmo_click_area.addEventListener( Event.ENTER_FRAME, btn_enter_north );


          var each_substring_north:Array = menu_label_North[i_north].split("|");
          btn_north.flashmo_button_label.fm_label.text = each_substring[0];
          btn_north.item_url = each_substring[1];
          main_menu_North.addChild(btn_north);
}


function btn_over_north(e:MouseEvent):void
{
          e.target.parent.over = true;
}


function btn_out_north(e:MouseEvent):void
{
          e.target.parent.over = false;
}


function btn_click_north(e:MouseEvent):void
{
          var mc= e.target.parent;
          if ( mc.item_url != undefined )
                    navigateToURL( new URLRequest( mc.item_url ), "_parent" );
          else
                    change_page_north(mc.item_no);
}


function btn_enter_north(e:Event):void
{
          var mc_north = e.target.parent;
          if ( mc_north.over == true )
                    mc_north.nextFrame();
          else
                    mc_north.prevFrame();
}


function change_page_north(no:Number):void
{
          for (var i:Number = 0; i < main_menu_North.numChildren; i++)
          {
                    var mc = MovieClip( main_menu_North.getChildAt(i) );
                    mc.over = false;
                    mc.flashmo_click_area.visible = true;
                    mc.flashmo_click_area.addEventListener( MouseEvent.ROLL_OVER, btn_over_north );
                    mc.flashmo_click_area.addEventListener( MouseEvent.ROLL_OUT, btn_out_north );
                    mc.flashmo_click_area.addEventListener( MouseEvent.CLICK, btn_click_north );
          }
          var mc_selected = MovieClip( main_menu_North.getChildAt(no) );
          mc_selected.over = true;
          mc_selected.flashmo_click_area.visible = false;
          mc_selected.flashmo_click_area.removeEventListener( MouseEvent.ROLL_OVER, btn_over_north );
          mc_selected.flashmo_click_area.removeEventListener( MouseEvent.ROLL_OUT, btn_out_north );
          mc_selected.flashmo_click_area.removeEventListener( MouseEvent.CLICK, btn_click_north );

          page_north = no + 1;
          play();
}


change_page_north(0);// default page on load


flashmo_credit.addEventListener( MouseEvent.CLICK, goto_fm_north );


function goto_fm_north(e:MouseEvent):void
{
          navigateToURL( new URLRequest( "http://www.flashmo.com" ), "_parent" );
}


music_credit.addEventListener( MouseEvent.CLICK, goto_music_north );


function goto_music_north(e:MouseEvent):void
{
          navigateToURL( new URLRequest(
          "http://www.premiumbeat.com/royalty_free_music/byPiece.php?id=2614" ),
          "_blank" );
}
4

1 回答 1

0

我认为你的错误可能来自var mc = MovieClip( main_menu_North.getChildAt(i) );

孩子会应该是对的flashmo_button吗?如果你使用MovieClip(obj)你是说你想转换objMovieClip. 如果它已经是一个 MovieClip(或 MovieClip 的后代),您应该使用as MovieClip.

例如

var mc:MovieClip = main_menu_North.getChildAt(i) as MovieClip

事实上,你应该把它转换成一个DisplayObject类型,因为你不能保证它永远是一个MovieClip.

我可以看到的潜在空对象的另一个潜在区域是使用e.target.parent. 如果您试图获得点击按钮,您应该使用e.currentTargetsee here。在调用它们的方法之前测试你是否获得了一个有效的对象。

if(e.currentTarget && e.currentTarget.parent) {
    // now do something
}
于 2013-10-13T09:11:17.957 回答