Comunidad de diseño web y desarrollo en internet online

Eliminar e.target

Citar            
MensajeEscrito el 24 Jul 2012 11:02 pm
Saludos. De antemano muchas gracias a cualquiera que me ayude a resolver una incógnita. Estoy haciendo una aplicación Drag and Drop. De la cual tengo una clase en el .fla y algunas .as. Al arrastrar el objeto lo arrojo a una linea la cual adhiere a los circulos que arrastro a ella. Deseo que si los circulos no tocan las lineas se eliminen ( y se cree otro nuevo en la parte superior). Como estoy usando e.currentTarget no puedo usar removeChild para eliminarlo, como puedo hacerlo? Acá está el code

Código ActionScript :

 import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;

//Carga de XML
var myXML:XML = new XML();
var XML_URL:String = "sounds.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

var array_init_x:Array = [450,450,450];// posicion superior de circulos y cuadrados eje X
var array_init_y:Array = [100,150,200];// posicion superior de circulos y cuadrados eje Y
var hitTest_id_y:Array = [350,400,450];// posicion "barra" inferior en el eje Y
var hitTest_id_x:Number = 40;// posicion "barra" inferior en el eje X

var array_flecha_izq_x:Array = [410,410,410];// posicion X flecha izquierda
var array_flecha_izq_y:Array = [100,150,200];// posicion Y flecha izquierda

var array_flecha_der_y:Array = [100,150,200];// posicion X flecha derecha
var array_flecha_der_x:Array = [750,750,750];// posicion Y flecha derecha

var n:int = 0;// Variable para ciclo for global
var i:int = 0;// Variable para ciclo for anidado
var contadorFX:int;
var contadorScratch:int;
var contadorLoops:int;

var tmp:MovieClip;
var hit:MovieClip;
var cont:MovieClip;
var fle_izq:MovieClip;
var fle_der:MovieClip;

//Funcion que se ejecuta cuando termina la descarga.
function xmlLoaded(event:Event):void
{
   myXML = XML(myLoader.data);//Carga datos al objeto XML
   var array_length:Array = new Array();//Crea instancia Array

   array_length.push(myXML.fx.sonido.length());
   //Carga numero de datos de FX en Array (array_length);
   array_length.push(myXML.scratch.sonido.length());
   //Carga numero de datos de Scratch en Array (array_length);
   array_length.push(myXML.loops.sonido.length());
   //Carga numero de datos de Loops en Array (array_length;//array_length = [9,6,6];
   // Ciclo que toma como variable de restriccion el numero de nodos en el XML 
   for (n = 0; n < array_length.length; n++)
   {
      //Flechas
      for (i = 0; i < array_length[n]; i++)
      {
         fle_izq = new flecha_izquierda();
         fle_izq.x = array_flecha_izq_x[n];
         fle_izq.y = array_flecha_izq_y[n];

         fle_der = new flecha_derecha();
         fle_der.x = array_flecha_der_x[n];
         fle_der.y = array_flecha_der_y[n];

         addChild(fle_izq);
         addChild(fle_der);
         fle_izq.buttonMode = true;
         fle_der.buttonMode = true;

      }

      //Cuadrados
      for (i = 0; i < array_length[n]; i++)
      {
         cont = new forma_(n + 1);
         cont.x = array_init_x[n] + (cont.width + 5) * i;
         cont.y = array_init_y[n];
         cont.startX = cont.x;
         cont.startY = cont.y;
         addChild(cont);
      }

      //Circulos
      for (i = 0; i < array_length[n]; i++)
      {
         tmp = new audio(n + 1);
         tmp.x = array_init_x[n] + (tmp.width + 7) * i;
         tmp.y = array_init_y[n];
         tmp.startX = tmp.x;
         tmp.startY = tmp.y;
         tmp.buttonMode = true;
         addChild(tmp);

         if (n == 0)
         {
            tmp.name = (myXML.fx.sonido.@id[i]);
            contadorFX++;

         }
         if (n == 1)
         {
            tmp.name = (myXML.scratch.sonido.@id[i]);
            contadorScratch++;

         }
         if (n == 2)
         {
            tmp.name = (myXML.loops.sonido.@id[i]);
            contadorLoops++;

         }

      }

      //Barra Inferior
      for (i=0; i < 120; i++)
      {
         hit = new hitTest(n + 1);
         hit.x = hitTest_id_x + (hit.width) * i;
         hit.y = hitTest_id_y[n];
         addChild(hit);
      }

   }

   trace(contadorFX);
   trace(contadorScratch);
   trace(contadorLoops);

}


Tengo otras clases AS pero la que necesito arreglar es esta

Código ActionScript :

package 
{

   //Clase para los circulitos
   import flash.display.*;
   import flash.events.MouseEvent;

   public class audio extends MovieClip
   {
      public var id_audio:Number;
      public var startX:Number;
      public var startY:Number;
      var clon:MovieClip;
      var tmp:MovieClip;

      public function audio(id:Number):void
      {
         //constructor
         id_audio = id;
         addEventListener(MouseEvent.MOUSE_DOWN,mdown);
         addEventListener(MouseEvent.MOUSE_UP,mUp);


      }
      

      public function mdown(e:MouseEvent):void
      {
         e.currentTarget.startDrag();
         e.target.parent.addChild(e.target);
      }

      public function mUp(e:MouseEvent):void
      {
         e.currentTarget.stopDrag();
         //e.target.x = startX;
         //e.target.y = startY;
         
      
         
         if (e.currentTarget.id_audio == 1 && e.target.dropTarget.parent.id_hit == 1)
         {

            var enLaPista = e.target.dropTarget.parent;
            e.target.x = enLaPista.x;
            e.target.y = enLaPista.y;
            trace("circulo toco linea de tiempo (id = id_hit = 1)");
            trace(e.target.name);

         }
         
         else
         {

            if (e.currentTarget.id_audio == 2 && e.target.dropTarget.parent.id_hit == 2)
            {
               var enLaPista2 = e.target.dropTarget.parent;
               e.target.x = enLaPista2.x;
               e.target.y = enLaPista2.y;
               trace("circulo toco linea de tiempo (id = id_hit = 2)");
               trace(e.target.name);
            }
            else
            {

               if (e.currentTarget.id_audio == 3 && e.target.dropTarget.parent.id_hit == 3)
               {
                  var enLaPista3 = e.target.dropTarget.parent;
                  e.target.x = enLaPista3.x;
                  e.target.y = enLaPista3.y;
                  trace("circulo toco linea de tiempo (id = id_hit = 3)");
                  trace(e.target.name);

               }
               else
               {
            
                  e.currentTarget.x = startX;
                  e.currentTarget.y = startY;

               }
            }
         }
      }
   }
}





Sé que en esta parte debo eliminar el currentTarget, pero no sé como hacerlo, alguna sugerencia?

Código ActionScript :


else
{
e.currentTarget.x = startX;
e.currentTarget.y = startY;
}



Gracias por cualquier sugerencia

Por pezweb

13 de clabLevel



 

Flash Developer

chrome
Citar            
MensajeEscrito el 25 Jul 2012 02:05 pm
Lo primero es lo primero

removeChild(e.currentTarget)

Si te dice que un child no puede borrar al padre, llama a una función de un contenedor superior para que borre el e.currentTarget (en realidad se lo pasas como argumento)

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 26 Jul 2012 04:31 pm
Muchas gracias, lo resolví con esta línea

Código ActionScript :

e.target.parent.removeChild(e.currentTarget);

Por pezweb

13 de clabLevel



 

Flash Developer

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.