Dynamic diagram with XML and AS3 in Flash CS4

  • overdrive
  • Born
  • Born
  • overdrive
  • Posts: 1

Post 3+ Months Ago

Hello! I commissioned a mini dynamic application that could do graphics like they show in the top, the mechanics is to read a file. xml and based on that create circles (atoms) and circles (genes) that orbit respectively, this not have to carry any type of animation only generate the graph, the problem is that there will always be the same elements not can!


I have little experience in AS3 but draw some static elements, and made the connection with xml, my big problem is to generate the algorithm that allows me to draw a certain number of elements and accommodate them in the right place, I have thought some type orbits but no movement!

This is the code that I have so far:
Code:

Code: [ Select ]

//Coneccion XML


var url:String="Molecula.xml";
var urlRequest:URLRequest=new URLRequest(url);
var urlLoader=new URLLoader(urlRequest);
var xml:XML;

urlLoader.addEventListener(Event.COMPLETE, onCompleteEvent );

function onCompleteEvent(e:Event) {

  xml=new XML(e.target.data);

  trace(xml.Marca.Nombre);
  trace("----------------");
  //trace(xml.Atomos.Atomo.NombreAtomo)
  var numAtomos=xml..Atomos.Atomo.length();

  for (var k:Number=0; k<numAtomos; k++) {

   trace(xml..Atomos.Atomo[k].NombreAtomo);

  }//Termina for

}//onCompleteEvent

//Termina XML

//Atomo - Grafica de Pie
import PieChartTest;
var AtomoGen:PieChartTest = new PieChartTest();
this.addChild(AtomoGen);
AtomoGen.x=190;
AtomoGen.y=100;


///////////////////////////////

//Elipse Central
var elipse:Sprite = new Sprite();
elipse.graphics.lineStyle(0,0x000000);
elipse.graphics.beginFill(0xCCCCCC);
elipse.graphics.drawEllipse(0,0,200, 150);//Valores (X,Y, Anchura, Altura)
elipse.graphics.endFill();


//Gen
var gen:Sprite = new Sprite();
gen.graphics.lineStyle(0,0x000000);
gen.graphics.beginFill(0x00B050);
gen.graphics.drawCircle(0,0,5);
gen.graphics.endFill();

var gen2:Sprite = new Sprite();
gen2.graphics.lineStyle(0,0x000000);
gen2.graphics.beginFill(0x00B050);
gen2.graphics.drawCircle(0,0,5);
gen2.graphics.endFill();


//Gen
/*for (var i:Number=1;i==1;i++) {
  var gen:Sprite = new Sprite();
  gen.graphics.lineStyle(0,0x000000);
  gen.graphics.beginFill(0x00B050);
  gen.graphics.drawCircle(0,0,5);
  gen.graphics.endFill();
  this.addChild(gen);
}*/

//Formatos de Texto
var formatoTexto:TextFormat = new TextFormat();
formatoTexto.color=0x000000;
formatoTexto.size=25;
formatoTexto.align='center';
formatoTexto.font='arial';
//
var formatoTextoGen:TextFormat = new TextFormat();
formatoTextoGen.color=0x000000;
formatoTextoGen.size=8;
formatoTextoGen.align='center';
formatoTextoGen.font='arial';


//Texto Elipse
var textfieldelipse:TextField = new TextField();
textfieldelipse.defaultTextFormat=formatoTexto;
textfieldelipse.text="Idea Central";
textfieldelipse.autoSize=TextFieldAutoSize.CENTER;
textfieldelipse.y=55;
textfieldelipse.x=30;
textfieldelipse.border=false;
textfieldelipse.background=false;
textfieldelipse.mouseEnabled=false;

//Texto Atomo
var textfieldatomo:TextField = new TextField();
textfieldatomo.defaultTextFormat=formatoTexto;
textfieldatomo.text="Atomo";
textfieldatomo.autoSize=TextFieldAutoSize.CENTER;
textfieldatomo.y=textfieldatomo.y-20;
textfieldatomo.x=textfieldatomo.x-50;
textfieldatomo.border=false;
textfieldatomo.background=false;
textfieldatomo.mouseEnabled=false;

//Texto Gen
var textfieldgen:TextField = new TextField();
textfieldgen.defaultTextFormat=formatoTextoGen;
textfieldgen.text="Gen de Versatil";
textfieldgen.autoSize=TextFieldAutoSize.CENTER;
textfieldgen.y=-20;
textfieldgen.x=-25;
textfieldgen.border=false;
textfieldgen.background=false;
textfieldgen.mouseEnabled=false;

//Finalmente dibujamos los elemntos
this.addChild(elipse);
elipse.x=237;
elipse.y=150;
elipse.addChild(textfieldelipse);
//

this.addChild(gen);
gen.x=250;
gen.y=50;
gen.addChild(textfieldgen);

this.addChild(gen2);
gen2.x=150;
gen2.y=50;
gen2.addChild(textfieldgen);


AtomoGen.addChild(textfieldatomo);
  1. //Coneccion XML
  2. var url:String="Molecula.xml";
  3. var urlRequest:URLRequest=new URLRequest(url);
  4. var urlLoader=new URLLoader(urlRequest);
  5. var xml:XML;
  6. urlLoader.addEventListener(Event.COMPLETE, onCompleteEvent );
  7. function onCompleteEvent(e:Event) {
  8.   xml=new XML(e.target.data);
  9.   trace(xml.Marca.Nombre);
  10.   trace("----------------");
  11.   //trace(xml.Atomos.Atomo.NombreAtomo)
  12.   var numAtomos=xml..Atomos.Atomo.length();
  13.   for (var k:Number=0; k<numAtomos; k++) {
  14.    trace(xml..Atomos.Atomo[k].NombreAtomo);
  15.   }//Termina for
  16. }//onCompleteEvent
  17. //Termina XML
  18. //Atomo - Grafica de Pie
  19. import PieChartTest;
  20. var AtomoGen:PieChartTest = new PieChartTest();
  21. this.addChild(AtomoGen);
  22. AtomoGen.x=190;
  23. AtomoGen.y=100;
  24. ///////////////////////////////
  25. //Elipse Central
  26. var elipse:Sprite = new Sprite();
  27. elipse.graphics.lineStyle(0,0x000000);
  28. elipse.graphics.beginFill(0xCCCCCC);
  29. elipse.graphics.drawEllipse(0,0,200, 150);//Valores (X,Y, Anchura, Altura)
  30. elipse.graphics.endFill();
  31. //Gen
  32. var gen:Sprite = new Sprite();
  33. gen.graphics.lineStyle(0,0x000000);
  34. gen.graphics.beginFill(0x00B050);
  35. gen.graphics.drawCircle(0,0,5);
  36. gen.graphics.endFill();
  37. var gen2:Sprite = new Sprite();
  38. gen2.graphics.lineStyle(0,0x000000);
  39. gen2.graphics.beginFill(0x00B050);
  40. gen2.graphics.drawCircle(0,0,5);
  41. gen2.graphics.endFill();
  42. //Gen
  43. /*for (var i:Number=1;i==1;i++) {
  44.   var gen:Sprite = new Sprite();
  45.   gen.graphics.lineStyle(0,0x000000);
  46.   gen.graphics.beginFill(0x00B050);
  47.   gen.graphics.drawCircle(0,0,5);
  48.   gen.graphics.endFill();
  49.   this.addChild(gen);
  50. }*/
  51. //Formatos de Texto
  52. var formatoTexto:TextFormat = new TextFormat();
  53. formatoTexto.color=0x000000;
  54. formatoTexto.size=25;
  55. formatoTexto.align='center';
  56. formatoTexto.font='arial';
  57. //
  58. var formatoTextoGen:TextFormat = new TextFormat();
  59. formatoTextoGen.color=0x000000;
  60. formatoTextoGen.size=8;
  61. formatoTextoGen.align='center';
  62. formatoTextoGen.font='arial';
  63. //Texto Elipse
  64. var textfieldelipse:TextField = new TextField();
  65. textfieldelipse.defaultTextFormat=formatoTexto;
  66. textfieldelipse.text="Idea Central";
  67. textfieldelipse.autoSize=TextFieldAutoSize.CENTER;
  68. textfieldelipse.y=55;
  69. textfieldelipse.x=30;
  70. textfieldelipse.border=false;
  71. textfieldelipse.background=false;
  72. textfieldelipse.mouseEnabled=false;
  73. //Texto Atomo
  74. var textfieldatomo:TextField = new TextField();
  75. textfieldatomo.defaultTextFormat=formatoTexto;
  76. textfieldatomo.text="Atomo";
  77. textfieldatomo.autoSize=TextFieldAutoSize.CENTER;
  78. textfieldatomo.y=textfieldatomo.y-20;
  79. textfieldatomo.x=textfieldatomo.x-50;
  80. textfieldatomo.border=false;
  81. textfieldatomo.background=false;
  82. textfieldatomo.mouseEnabled=false;
  83. //Texto Gen
  84. var textfieldgen:TextField = new TextField();
  85. textfieldgen.defaultTextFormat=formatoTextoGen;
  86. textfieldgen.text="Gen de Versatil";
  87. textfieldgen.autoSize=TextFieldAutoSize.CENTER;
  88. textfieldgen.y=-20;
  89. textfieldgen.x=-25;
  90. textfieldgen.border=false;
  91. textfieldgen.background=false;
  92. textfieldgen.mouseEnabled=false;
  93. //Finalmente dibujamos los elemntos
  94. this.addChild(elipse);
  95. elipse.x=237;
  96. elipse.y=150;
  97. elipse.addChild(textfieldelipse);
  98. //
  99. this.addChild(gen);
  100. gen.x=250;
  101. gen.y=50;
  102. gen.addChild(textfieldgen);
  103. this.addChild(gen2);
  104. gen2.x=150;
  105. gen2.y=50;
  106. gen2.addChild(textfieldgen);
  107. AtomoGen.addChild(textfieldatomo);
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 15 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.