Ver Mensaje Individual
  #7 (permalink)  
Antiguo 15/11/2010, 19:44
Avatar de TMeister
TMeister
Crazy Coder
 
Fecha de Ingreso: enero-2002
Ubicación: En la Oficina
Mensajes: 2.880
Antigüedad: 22 años, 3 meses
Puntos: 193
Respuesta: Tratando de migrar a as3

Aquí mas detallado..


Código actionscript:
Ver original
  1. import flash.events.Event;
  2. import flash.display.MovieClip;
  3.  
  4. /**
  5. * Array para guardar los objetos creados
  6. */
  7. var store:Array = [];
  8.  
  9. /**
  10. *Creamos los objetos desde un MovieClip en la libreria y los ponemos en el stage de modo random
  11. */
  12.  
  13. for (var i:int = 0; i<5; i++)
  14. {
  15.     var tmp:ball = new ball();
  16.     store.push( tmp );
  17.     /*Damos un nombre para poder acceder al clip fuera del for */
  18.     tmp.name = "ball"+i;
  19.     tmp.x = Math.random() * stage.stageWidth;
  20.     tmp.y = Math.random() * stage.stageHeight;
  21.     addChild( tmp );
  22. }
  23.  
  24. /*
  25. * Accedemos a un objeto por su nombre
  26. */
  27. var ball2:MovieClip = getChildByName('ball2') as MovieClip;
  28. var ranx;int;
  29. var rany:int;
  30.  
  31. /*
  32. * Listener para animar un objeto solo como ejemplo
  33. */
  34.  
  35. addEventListener(Event.ENTER_FRAME, moveIt);
  36.  
  37. function moveIt(e:Event)
  38. {
  39.     ball2.x += ((ranx-ball2.x)/10);
  40.     ball2.y += ((rany-ball2.y)/10);
  41.     if (Math.round(ball2.x) == ranx || Math.round(ball2.y) == rany) {
  42.         moveAll();
  43.         newcoords();
  44.     }
  45. }
  46.  
  47. /*
  48. * Accedemos a los Objetos guardados en el array..
  49. */
  50. function moveAll()
  51. {
  52.     for each ( var ball:MovieClip in store)
  53.     {
  54.         ball.x = Math.random() * stage.stageWidth;
  55.         ball.y = Math.random() * stage.stageHeight;
  56.     }
  57. }
  58.  
  59. /*
  60. * funcion de ayuda para generar nuevas coordenadas..
  61. */
  62. function newcoords() {
  63.     ranx = Math.round((Math.random ()*stage.stageWidth));
  64.     rany = Math.round ((Math.random ()*stage.stageHeight));
  65. }