Ciclo del carbono.

Anuncio
Ciclo del carbono.
Ejercicio Interactivo del ciclo de Carbono
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(res1,res2,res3,res4,luz,nut1,nut2,org1,org2,org3,desco
m,at);
}
private function getPosition(target:Object):void
{
xPos = target.x;
yPos = target.y;
nombre=target.name.substring(0,3);
}
private function dragObject(e:MouseEvent):void
{
getPosition(e.target);
e.target.startDrag(true);
}
private function stopDragObject(e:MouseEvent):void
{
var flag:Boolean=false;
trace(e.target.name);
if (e.target.hitTestObject(getChildByName("zona" +
e.target.name)))
{
e.target.x = getChildByName("zona" +
e.target.name).x;
e.target.y = getChildByName("zona" +
e.target.name).y;
flag=true;
//e.target.play();
}
else if(nombre=="res"){
for(var i:int=1;i<5;i++){
//trace("Zonabioo"+i);
if(e.target.hitTestObject(getChildByName("zonares"+i.valueOf()))) {
e.target.x=getChildByName("zonares"+i).x;
e.target.y=getChildByName("zonares"+i).y;
flag=true;
}
}
}
else if(nombre=="nut"){
for(var i:int=1;i<3;i++){
//trace("Zonaabio"+i);
//trace(e.target.hitTestObject(getChildByName("Zona"+nombre+i.value
Of())));
if(e.target.hitTestObject(getChildByName("zonanut"+i))) {
e.target.x=getChildByName("zonanut"+i).x;
e.target.y=getChildByName("zonanut"+i).y;
flag=true;
}
}
}
else if(nombre=="org"){
for(var i:int=1;i<4;i++){
//trace("Zonabioo"+i);
if(e.target.hitTestObject(getChildByName("zonaorg"+i.valueOf()))) {
e.target.x=getChildByName("zonaorg"+i).x;
e.target.y=getChildByName("zonaorg"+i).y;
flag=true;
}
}
}
if(!flag){
e.target.x=xPos;
e.target.y=yPos;
}
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