2013-03-22 44 views
1

我想提出一个照相馆很简单,但一个孩子,当我尝试分类我不断收到此错误,当我按下按钮的照片。该分类按钮可以去除大拇指,但不会分拣它们。AS3错误:提供的DisplayObject必须是调用

引发ArgumentError:错误#2025:提供的DisplayObject必须是调用者的子。 在flash.display一::级DisplayObjectContainer/removeChild之() 在myGallery_fla :: MainTimeline/removeAllMovieClips() 在myGallery_fla :: MainTimeline/loadConcert()

我拉我的头发试图修复它,我只是不能得到它。任何帮助将非常感激:)

继承人我的代码,它的相当长:

//declaring my permanant variables. 
var columns:Number; 
var my_x:Number; 
var my_y:Number; 
var my_thumb_width:Number; 
var my_thumb_height:Number; 
var my_images:XMLList; 
var my_total:Number; 

var currentCategory:String = "concert"; 

//new movie clip to hold images. 
var container_mc:MovieClip; 
//new movie clip to do progress bar. 
var preloaders_mc:MovieClip; 
//to give full image a hand cursor. button mode does not work on loaders so i must create a new mc. 
var full_mc:MovieClip; 

var x_counter:Number = 0; 
var y_counter:Number = 0; 

//array to hold tweens. 
var my_tweens:Array = []; 
//array for categorizing 
var movieClipArray:Array=new Array(); 

//permenant vars for tweens. 
var container_mc_tween:Tween; 
var full_tween:Tween; 

var myNewXML:XMLList; 
var myXML:XML; 
//creater new urlLoader to load xml 
var myXMLLoader:URLLoader = new URLLoader(); 
myXMLLoader.load(new URLRequest("gallery.xml")); 
myXMLLoader.addEventListener(Event.COMPLETE, processXML); 


function processXML(e:Event):void{ 
    //temperary will be deleted when executed. 
    myXML= new XML(e.target.data); 
    processXMLData(); 
} 

function processXMLData() 
{ 
myNewXML = myXML.GALLERY.(CATEGORY == currentCategory); 
//trace(myNewXML); 
    //set the values of the images 
    //@ retrives the attributes I need 
    columns = [email protected]; 
    my_x = [email protected]N; 
    my_y = [email protected]; 
    my_thumb_width = [email protected]; 
    my_thumb_height = [email protected]; 
    my_images = myXML.IMAGE; 
    my_total = my_images.length(); 



    createContainer(); 
    callThumbs(); 

    //instance of the URLLoader and its associated event listener are 
    //both not required once we extract the data from our XML file. 
    //delete these two once that task is finished. 
    myXMLLoader.removeEventListener(Event.COMPLETE, processXML); 
    myXMLLoader = null; 

} 


function createContainer():void{ 
    //creating movieclip to hold images 
    container_mc = new MovieClip(); 



    //I position the MovieClip in accordance to the variables from xml. 
    container_mc.x = my_x; 
    container_mc.y = my_y; 
    addChild(container_mc); 

    //regestering the click event to the parent instead of the thumbs 
    //instead of to each thumb. 
    container_mc.addEventListener(MouseEvent.CLICK, callFull); 
    //thumbs hover effects 
    container_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver); 
    container_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut); 
    container_mc.buttonMode = true; 

    preloaders_mc = new MovieClip(); 
    preloaders_mc.x = container_mc.x; 
    preloaders_mc.y = container_mc.y; 

    //movieClipArray.push(container_mc); 
    //trace(movieClipArray); 
    addChild(preloaders_mc); 
    //trace(movieClipArray); 
} 

function callThumbs():void{ 
    //loop will cycle through as long as it does not exceed the total num of images. 
    for (var i:Number = 0; i < my_total; i++){ 

     //retrives the url of the thumbs. 
     var thumb_url = my_images[i][email protected]; 
     //creates temperary instance of loader 
     var thumb_loader = new Loader(); 
     //loads the thumbs 
     thumb_loader.load(new URLRequest(thumb_url)); 
     thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded); 

     //unique reference to each thumb to tell us what image to load from the xml array. 
     //thus I set thumb's name property as its number in the XML list. 
     thumb_loader.name = i; 

     //position the thumbs horizontially 
     thumb_loader.x = (my_thumb_width + 30)* x_counter; 

     thumb_loader.y = (my_thumb_height + 30)* y_counter; 


     if(x_counter+1 < columns){ 
      x_counter++; 
     } 
     else{ 
      x_counter = 0; 
      y_counter ++; 
     } 

     var preloader_pb:ProgressBar = new ProgressBar(); 
     preloader_pb.source = thumb_loader.contentLoaderInfo; 
     preloader_pb.x = thumb_loader.x; 
     preloader_pb.y = thumb_loader.y; 
     preloader_pb.width = my_thumb_width; 
     preloader_pb.height = my_thumb_height; 
     preloaders_mc.addChild(preloader_pb); 

     preloader_pb.addEventListener(Event.COMPLETE, donePb); 
    } 
} 


//loads the instances of thumbs to container_mc to be visable. 
function thumbLoaded(e:Event):void{ 
    var my_thumb:Loader = Loader(e.target.loader); 
    container_mc.addChild(my_thumb); 
    //trace(container_mc); 
    stage.addChild(container_mc); 
    movieClipArray.push(container_mc); 
    //trace(movieClipArray.length); 

    //Fading in Each Thumb once it Loads. 
    my_tweens[Number(my_thumb.name)]=new Tween(my_thumb, "alpha", Strong.easeIn, 0,1,0.5, true); 

    //event listener used to check the download process of our thumbnails. 
    //These are only used once in the gallery and are never required again. 
    my_thumb.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoaded); 

} 

//loads the full image by using an instance of loader class. 
function callFull(e:MouseEvent):void{ 
    var full_loader:Loader = new Loader(); 
    var full_url = my_images[e.target.name][email protected]; 
    full_loader.load(new URLRequest(full_url)); 
    //will only be displayed after it fully loaded 
    full_loader.contentLoaderInfo.addEventListener(Event.INIT, fullLoaded); 

    var full_pb:ProgressBar = new ProgressBar(); 
    full_pb.source = full_loader.contentLoaderInfo; 
    full_pb.x = 100; 
    full_pb.y = 400; 
    preloaders_mc.addChild(full_pb); 

    full_pb.addEventListener(Event.COMPLETE, donePb); 


    container_mc.removeEventListener(MouseEvent.CLICK, callFull); 
    container_mc.buttonMode = false; 
    //hover effects for full. 
    container_mc.removeEventListener(MouseEvent.MOUSE_OVER, onOver); 
    container_mc.removeEventListener(MouseEvent.MOUSE_OUT, onOut); 
    //Fading In and Out the Entire Gallery when a full image is shown 
    container_mc_tween = new Tween(container_mc, "alpha", Strong.easeIn, 1,0.5,0.5, true); 

} 

//will load the full pic and position it 
function fullLoaded(e:Event):void{ 
    //for the hand cursor. 
    full_mc = new MovieClip(); 
    full_mc.buttonMode = true; 
    addChild (full_mc); 
    var my_loader:Loader = Loader(e.target.loader); 
    full_mc.addChild(my_loader); // This line was addChild(my_loade), just add full_mc. before it. 
    //Fading In of Full Image 
    full_tween = new Tween(my_loader, "alpha", Strong.easeIn, 0,1,0.5, true); 
    my_loader.x = 150; 
    my_loader.y = 100 
    my_loader.addEventListener(MouseEvent.CLICK,removeFull); 

    my_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, fullLoaded); 
    //stage.addEventListener(MouseEvent.ROLL_OUT, disappear,false,0,true); 
    full_mc.addEventListener(MouseEvent.ROLL_OVER,appear); 

    } 




function removeFull(e:MouseEvent):void{ 
var my_loader:Loader = Loader (e.currentTarget); 
full_tween = new Tween(my_loader, "alpha", Strong.easeOut, 1,0,0.5, true); 
full_tween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished); 

container_mc_tween = new Tween(container_mc, "alpha", Strong.easeOut, 0.5,1,0.5, true); 
my_loader.addEventListener(MouseEvent.ROLL_OUT,disappear); 
} 

function tweenFinished (e:TweenEvent):void{ 
var my_loader:Loader = Loader (e.target.obj); 
my_loader.unload(); 
full_mc.removeChild(my_loader); // This line was removeChid(my_loader), just add full_mc before it. 
removeChild(full_mc); 
full_mc = null; 

container_mc.addEventListener(MouseEvent.CLICK, callFull); 
container_mc.buttonMode = true; 
container_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver); 
container_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut); 

var my_tween:Tween = Tween(e.target); 
my_tween.removeEventListener(TweenEvent.MOTION_FINISH, tweenFinished); 
} 

function donePb (e:Event):void{ 
    var my_pb:ProgressBar = ProgressBar(e.target); 
    preloaders_mc.removeChild(my_pb); 
    my_pb.removeEventListener(Event.COMPLETE, donePb); 
} 

function onOver (e:MouseEvent):void{ 
    var my_thumb:Loader = Loader(e.target); 
    my_thumb.alpha = 0.5; 
} 

function onOut (e:MouseEvent):void{ 
    var my_thumb:Loader = Loader (e.target); 
    my_thumb.alpha = 1; 
} 

//category buttons 
var animal_btn:SimpleButton = new animals_mc(); 
addChild(animal_btn); 
animal_btn.x = 50; 
animal_btn.y =550; 

var concert_btn:SimpleButton = new concert_mc(); 
addChild(concert_btn); 
concert_btn.x = 180; 
concert_btn.y =550; 

var festival_btn:SimpleButton = new festival_mc(); 
addChild(festival_btn); 
festival_btn.x = 310; 
festival_btn.y =550; 

var flowers_btn:SimpleButton = new flowers_mc(); 
addChild(flowers_btn); 
flowers_btn.x = 440; 
flowers_btn.y =550; 


flowers_btn.addEventListener(MouseEvent.CLICK, loadFlowers); 
function loadFlowers(event:MouseEvent) 
{ 
    currentCategory = "flower"; 
    removeAllMovieClips(); 
    processXMLData(); 
} 

animal_btn.addEventListener(MouseEvent.CLICK, loadAnimals); 
function loadAnimals(event:MouseEvent) 
{ 
    currentCategory = "animals"; 
    removeAllMovieClips(); 
    processXMLData(); 
} 

concert_btn.addEventListener(MouseEvent.CLICK, loadConcert); 
function loadConcert(event:MouseEvent) 
{ 
    currentCategory = "concert"; 
    removeAllMovieClips(); 
    processXMLData(); 
} 

festival_btn.addEventListener(MouseEvent.CLICK, loadFestival); 
function loadFestival(event:MouseEvent) 
{ 
    currentCategory = "festival"; 
    removeAllMovieClips(); 
    processXMLData(); 
} 

function removeAllMovieClips(){ 
    trace(movieClipArray.length); 
    for (var i =0; i<movieClipArray.length; i++){ 
     stage.removeChild(movieClipArray[i]); 
    } 
    movieClipArray = []; 
    //trace(myMovieClipsOnStage); 

} 

var menu_mc:MovieClip = new fullPicMenu_mc(); 
addChild(menu_mc); 
menu_mc.x = 150; 
menu_mc.y =460; 
menu_mc.visible= false; 




var share_btn:SimpleButton = new share_mc(); 
addChild(share_btn); 
share_btn.x = 80; 
share_btn.y =350; 
share_btn.visible= false; 

var fav_btn:SimpleButton = new fav_mc(); 
addChild(fav_btn); 
fav_btn.x = 93; 
fav_btn.y =400; 
fav_btn.visible= false; 

var caption_btn:SimpleButton = new caption_mc(); 
addChild(caption_btn); 
caption_btn.x = 80; 
caption_btn.y =460; 
caption_btn.visible= false; 

回答

0

你是推比一次相同container_mc更进movieClipArray,那么你正试图从两次舞台中删除。无论是每一个拇指被加载,或完全摆脱了阵列的时间使一个新的容器中,在thumbLoaded()功能,因为你只有一个容器。

+0

我只推阵一次,其他推被注释掉注释掉。如果我摆脱我的阵营altogeter我将如何删除舞台上目前的类别? – 2013-03-22 09:46:47

+0

你是馅这一切变成'container_mc'了,所以只是删除MC起飞阶段,并删除链接,所以MC及其所有后代将得到GC'd。 – Vesper 2013-03-22 10:08:21

+0

所以在我的代码到处删除在container_mc? – 2013-03-22 10:14:12

0
function removeAllMovieClips(){ 
    trace(movieClipArray.length); 
    for (var i =0; i<movieClipArray.length; i++){ 
     if(movieClipArray[i] is DisplayObject && movieClipArray[i].parent == stage) 
      stage.removeChild(movieClipArray[i]); 
    } 
    movieClipArray = []; 
} 

我没有经历所有的代码,找出为什么你的影片剪辑是不是阶段的孩子,但是这将阻止错误。

你也可以做

if(movieClipArray[i].parent) movieClipArray[i].parent.removeChild(movieClipArray[i]); 
+0

是啊同样的事情仍然发生,当我击中类别按钮它只是将拇指钉下移动。如果我继续点击类别按钮,它只是在屏幕下移动。我也得到这个输出错误:类型错误:错误#1009:无法访问空对象引用的属性或方法。 \t at myGallery_fla :: MainTimeline/processXMLData() \t at myGallery_fla :: MainTimeline/loadConcert() – 2013-03-22 10:05:33

+0

这对于我们来说是非常多的代码来调试。你应该启动一个调试来发现它在哪一行出现错误。 ther是一个在你的processXMLData()函数中为null的对象,代码在那里停止。我不能说它是哪个对象。 – Boris 2013-03-22 10:17:12

+0

是啊我知道谢谢你的帮助:) – 2013-03-22 10:18:42

相关问题