Flujo de materia y energía

Anuncio
Flujo de materia y energía
Ejercicio Interactivo de Ecología y medio ambiente (Ecosistemas)
Código:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite
{
var xPos:int;
var yPos:int;
var nombre:String;
public function Main():void
{
addListeners(na1,na2,ry1,ry2,anima1,anima2,anima3,anima4);
anima1.visible=false;
anima2.visible=false;
anima3.visible=false;
anima4.visible=false;
}
private function getPosition(target:Object):void
{
xPos = target.x;
yPos = target.y;
nombre=target.name.substring(0,2);
}
private function dragObject(e:MouseEvent):void
{
getPosition(e.target);
e.target.startDrag(true);
}
private function stopDragObject(e:MouseEvent):void
{
var flag:Boolean=false;
trace(nombre);
if(nombre=="na"){
if(e.target.hitTestObject(getChildByName("zonana1"))) {
e.target.x=getChildByName("zonana1").x;
e.target.y=getChildByName("zonana1").y;
e.target.visible = false;
getChildByName("zonana1").visible=false;
anima1.visible=true;
anima1.play();
flag=true;
}else
if(e.target.hitTestObject(getChildByName("zonana2"))) {
e.target.x=getChildByName("zonana2").x;
e.target.y=getChildByName("zonana2").y;
e.target.visible = false;
getChildByName("zonana2").visible=false;
anima2.visible=true;
anima2.play();
flag=true;
}
}else if(nombre=="ry"){
if(e.target.hitTestObject(getChildByName("zonary1"))) {
e.target.x=getChildByName("zonary1").x;
e.target.y=getChildByName("zonary1").y;
e.target.visible = false;
getChildByName("zonary1").visible=false;
anima3.visible=true;
anima3.play();
flag=true;
}else
if(e.target.hitTestObject(getChildByName("zonary2"))) {
e.target.x=getChildByName("zonary2").x;
e.target.y=getChildByName("zonary2").y;
e.target.visible = false;
getChildByName("zonary2").visible=false;
anima4.visible=true;
anima4.play();
flag=true;
}
}
trace(flag);
if(!flag){
e.target.x=xPos;
e.target.y=yPos;
flag=false;
}
e.target.stopDrag();
}
private function addListeners(... objects):void
{
for (var i:int = 0; i < objects.length; i++)
{
objects[i].addEventListener(MouseEvent.MOUSE_DOWN,
dragObject);
objects[i].addEventListener(MouseEvent.MOUSE_UP,
stopDragObject);
}
}
}
}
Descargar