私のクラスはのAS3のremoveChildエラー
メインです - createasサイト サイト - - プリローダー プリローダーを作成し、メインメニューのボタンがクリックされたときにメインメニュー
を作成し、そのオブジェクトを作成します。そして、別のものがクリックされると、そのオブジェクトを削除する必要があります。取っ手部分がちょっと乱雑になった。
package src
{
import com.greensock.TweenLite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
/**
$(CBI)* ...
$(CBI)* @author servet
$(CBI)*/
public class MainMenu extends MovieClip
{
public var filmlerButton:MovieClip;
public var filmleralt:FilmAltButtonlar;
private var ANASAYFA_ORIGINAL_Y:Number;
private var HAKKIMIZDA_ORIGINAL_Y:Number;
private var FILMLER_ORIGINAL_Y:Number;
private var DAGITIM_ORIGINAL_Y:Number;
private var state:String;
public function MainMenu()
{
init();
}
private function init():void
{
repos();
assignOriginalHeights();
state = " ";
filmlerButton.filmlerhitarea.alpha = 0;
anasayfaButton.addEventListener(MouseEvent.CLICK, onAnasayfaClick);
hakkimizdaButton.addEventListener(MouseEvent.CLICK, onhakkimizdaClick);
filmlerButton.filmlerhitarea.addEventListener(MouseEvent.CLICK, onfilmlerClick);
dagitimButton.addEventListener(MouseEvent.CLICK, ondagitimClick);
}
private function assignOriginalHeights():void
{
ANASAYFA_ORIGINAL_Y = anasayfaButton.y;
HAKKIMIZDA_ORIGINAL_Y = hakkimizdaButton.y;
FILMLER_ORIGINAL_Y = filmlerButton.y;
DAGITIM_ORIGINAL_Y = dagitimButton.y;
//trace(ANASAYFA_ORIGINAL_Y, HAKKIMIZDA_ORIGINAL_Y, FILMLER_ORIGINAL_Y, DAGITIM_ORIGINAL_Y);
}
private function ondagitimClick(e:MouseEvent):void
{
if (state != "anasayfa"&&state!="hakkimizda"&&state!="filmler"&&state!="dagitim") {
state = "dagitim";
traceState();
dagitimButton.gotoAndStop(2);
}else {
state = " ";
traceState();
closeAllMenus();
}
}
private function onfilmlerClick(e:MouseEvent):void
{
if (state != "anasayfa"&&state!="hakkimizda"&&state!="filmler"&&state!="dagitim") {
closeAllMenus();
state = "filmler";
traceState();
filmlerButton.gotoAndStop(2);
filmleralt = new FilmAltButtonlar();
addChild(filmleralt);
filmleralt.name = "trouble";
//OBJECT ADDED HERE
TweenLite.to(dagitimButton, 1, {y:DAGITIM_ORIGINAL_Y+400 });
}else {
state = " ";
traceState();
closeAllMenus();
}
}
private function onhakkimizdaClick(e:MouseEvent):void
{
if (state != "anasayfa"&&state!="hakkimizda"&&state!="filmler"&&state!="dagitim") {
closeAllMenus();
state = "hakkimizda";
traceState();
hakkimizdaButton.gotoAndStop(2);
TweenLite.to(filmlerButton, 1, {y:FILMLER_ORIGINAL_Y+200 });
TweenLite.to(dagitimButton, 1, {y:DAGITIM_ORIGINAL_Y+200 });
}else {
state = " ";
traceState();
closeAllMenus();
}
}
private function onAnasayfaClick(e:MouseEvent):void //&& girecek
{
if (state != "anasayfa"&&state!="hakkimizda"&&state!="filmler"&&state!="dagitim") {
closeAllMenus();
state = "anasayfa";
traceState();
anasayfaButton.gotoAndStop(2);
TweenLite.to(hakkimizdaButton, 1, {y:hakkimizdaButton.y+200 });
TweenLite.to(filmlerButton, 1, {y:filmlerButton.y+200 });
TweenLite.to(dagitimButton, 1, {y:dagitimButton.y+200 });
}else {
state = " ";
traceState();
closeAllMenus();
}
}
private function closeAllMenus() {
TweenLite.to(hakkimizdaButton, 1, {y:HAKKIMIZDA_ORIGINAL_Y });
TweenLite.to(filmlerButton, 1, {y:FILMLER_ORIGINAL_Y });
TweenLite.to(dagitimButton, 1, { y:DAGITIM_ORIGINAL_Y });
anasayfaButton.gotoAndStop(1);
hakkimizdaButton.gotoAndStop(1);
filmlerButton.gotoAndStop(1);
dagitimButton.gotoAndStop(1);
//NEED TO REMOVE OBJECT HERE
//BUT THIS FUNCTION GETS CALLED A LOT
//SO I NEED TO CHECK IF THE OBJECT EXISTS
//BEFORE TRYING TO REMOVE TO AVOID AN NULL
//OBJECT REFERENCE SO I DO:
if (getChildByName(filmleralt.name) != null) {
removeFilmleralt();
}
}
private function removeFilmleralt() {
Main.instance.narfilm.mainmenu.removeChild(filmleralt);
}
private function traceState() {
trace("current state is: "+state);
}
public function repos():void //call on stage resize so it aligns to left babs
{
x = Main.instance.canvaswidth;
}
}
}
重要な部分は:
//NEED TO REMOVE OBJECT HERE
//BUT THIS FUNCTION GETS CALLED A LOT
//SO I NEED TO CHECK IF THE OBJECT EXISTS
//BEFORE TRYING TO REMOVE TO AVOID AN NULL
//OBJECT REFERENCE SO I DO:
if (getChildByName(filmleralt.name) != null) {
removeFilmleralt();
}
これは私がnullのオブジェクト参照のエラーを取得する部分です。
私は何が欠けていますか?