вот мои занятия
Main - создает предзагрузчик
Preloader - создать как сайт
Сайт - создает MainMenu
при нажатии кнопки в главном меню создается объект. И когда щелкают по другому, этот объект должен быть удален. Удаляющая часть стала немного грязной.
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();
}
это часть, где я получаю ошибку ссылки на нулевой объект.
что мне не хватает?