Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it L'avatar di DeR
    Registrato dal
    Mar 2003
    Messaggi
    975

    AS3 Problemi con removeChild()

    Ragazzi, ho un mc in libreria che ho esportato sul primo fotogramma e per actionscipt, il nome è "bolla"

    l'oggetto viene inserito sullo stage con il comando addChild(bolla);

    Fin qui tutto bene, il problema nasce quando ad un btn presente sullo stage ho associato il codice removeChild(bolla), non succede niente e il compilatore mi ritorna questo errore:



    ArgumentError: Error #2025: Il valore fornito per DisplayObject deve essere un elemento secondario del chiamante.
    at flash.display:isplayObjectContainer/removeChild()
    at index_codit__fla::MainTimeline/onReleaseBtnEntra()
    Ciao DeR

  2. #2
    var lamiabolla:bolla=new bolla();


    addChild(lamiabolla);

    removeChild(lamiabolla);
    Photogallery Flash Gratis - http://www.flashfiles.biz -
    Template in Flash con pannello di Amministrazione e deeplinking Guarda il template qui

  3. #3
    Utente di HTML.it L'avatar di DeR
    Registrato dal
    Mar 2003
    Messaggi
    975
    Ho provato, con lo stesso sistema riesco ad eliminare altri mc ma non la bolla, potrebbe dipendere dal fatto che si trova in un file as esterno, perche se inserisco il removechild subito sopo l'addchild funzione, mentre se lo aggiungo su un tasto no.
    Ciao DeR

  4. #4
    copia il tuo codice qui

    e fammi capire bene dove metti il codice per rimuovere
    Photogallery Flash Gratis - http://www.flashfiles.biz -
    Template in Flash con pannello di Amministrazione e deeplinking Guarda il template qui

  5. #5
    Utente di HTML.it L'avatar di DeR
    Registrato dal
    Mar 2003
    Messaggi
    975
    codice:
    //The number of bubbles we will have on the stage
    const NUMBER_OF_BUBBLES:uint = 60;
    
    //Save the stage width and height
    var stageWidth:Number = stage.stageWidth;
    var stageHeight:Number = stage.stageHeight;
    
    //This array will contain all the bubbles
    var bubbles:Array = new Array();
    
    //This loop creates and positions the bubbles to random locations
    for (var i:uint = 0; i < NUMBER_OF_BUBBLES; i++)
    {
    	//Create a new bubble
    	var bubble:Bubble = new Bubble();
    
    	//Assign  a random y coordinate (from 0 to 300)
    	bubble.y = Math.random() * stageHeight;
    
    	//Calculate the horizontal distance from the mouse cursor to the center of the stage
    	var distanceFromCenter:Number = mouseX - stageWidth / 2;
    
    	//Calculate the x coordinate (from -400 to 800)
    	bubble.x = Math.random() * stageWidth - Math.random() * distanceFromCenter * 2;
    
    	//Assign a random scale
    	bubble.scaleX = bubble.scaleY = Math.random() + 0.3;
    
    	//Assign a random alpha
    	bubble.alpha = Math.random() + 0.4;
    
    	//Assign a random current angle for the bubble
    	bubble.currentAngle = Math.random() * Math.PI * 2;
    
    	//Assign a random angle speed
    	bubble.angleSpeed = Math.random() * 0.1;
    
    	//Assign a random radius for the bubble
    	bubble.radius = Math.random() * 5;
    
    	//Assign a random y speed
    	bubble.ySpeed =  -  Math.random() * 0.5;
    
    	//Assign a random y acceleration speed
    	bubble.acceleration =  -  Math.random() * 0.2;
    	
    	
    
    	//Add the bubble to the bubbles array
    	bubbles.push(bubble);
    
    	//Add the bubble to the stage;
    	//addChild(bubble);
    	addChildAt(bubble, 1)
    	
    }
    
    //Add ENTER_FRAME listener for animating the bubbles
    addEventListener(Event.ENTER_FRAME, moveBubbles);
    
    //This function is called in each frame
    function moveBubbles(e:Event):void
    {
    	
    	
    	//Calculate the horizontal distance from the mouse cursor to the center of the stage
    	var distanceFromCenter:Number = mouseX - stage.stageWidth / 2;
    
    	//Calculate a new x speed for the bubbles
    	var xSpeed:Number = distanceFromCenter / 32;
    	
    
    	//Loop through the bubbles array
    	for (var i:uint = 0; i < bubbles.length; i++)
    	{
    		//Save the bubble to a local variable
    		var bubble:Bubble = (Bubble)(bubbles[i]);
    
    		//Update the ySpeed of the bubble (accelerate)
    		bubble.ySpeed +=  bubble.acceleration;
    
    		//Update the y coorinate
    		bubble.y +=  bubble.ySpeed;
    
    		//Update the current angle of the bubble
    		bubble.currentAngle +=  bubble.angleSpeed;
    
    		//Update the x coordinate
    		bubble.x +=  Math.sin(bubble.currentAngle) * bubble.radius + xSpeed;
    
    		//Check if the bubble is over the top of the stage
    		if (bubble.y < 0)
    		{
    			//Assign a new random x coordinate
    			bubble.y = stage.stageHeight;//stageHeight;
    			bubble.x = Math.random() * stage.stageWidth - Math.random() * distanceFromCenter * 2;
    
    			//Assign a new random current angle
    			bubble.currentAngle = Math.random() * Math.PI * 2;
    
    			//Assign a new random ySpeed
    			bubble.ySpeed =  -  Math.random() * 0.5;
    		}
    		
    		
    	}	
    
    }
    Ciao DeR

  6. #6
    ok ma non ho capito dove le vuoi rimuovere?
    Photogallery Flash Gratis - http://www.flashfiles.biz -
    Template in Flash con pannello di Amministrazione e deeplinking Guarda il template qui

  7. #7
    Utente di HTML.it L'avatar di DeR
    Registrato dal
    Mar 2003
    Messaggi
    975
    Ho un bottone sullo stage che dovrebbe cambiare frame e rimuovere le bolle.
    Ciao DeR

  8. #8
    le bolle sono tutte in un array e qui è perfetto

    aggiungi allo script una funzione per rimuverle usando l'array

    Codice PHP:
    function removeB (e:MouseEvent){

      for (var 
    =0ibubbles.length;i++){

      
    removeChild(bubbles[i]);  

    }  

    }
    //listener del bottone

    mybutton.addEventListener(MouseEvent.CLICK,removeB); 
    Photogallery Flash Gratis - http://www.flashfiles.biz -
    Template in Flash con pannello di Amministrazione e deeplinking Guarda il template qui

  9. #9
    Utente di HTML.it L'avatar di DeR
    Registrato dal
    Mar 2003
    Messaggi
    975
    Grazie 1000!
    Ciao DeR

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.