Import ActionScripts from another file

This is a continuing from http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20788652.html

How can I do same thing with another file.

I have solution from above working fine, But I need one more thing. To import another file that will draw the box over the triangles. I don;t want a link for it, just a box, so it can't be filled with color.

data_xml = new XML();
data_xml.path = this;
data_xml.ignoreWhite = true;
data_xml.onLoad = function(ok)
{
     if(ok){
          this.path.drawTriangles(this.firstChild.childNodes);
     } else {
          trace("XML FILE NOT FOUND");
     }
};
function drawTriangles(triangles_xml)
{
     var pen = this.createEmptyMovieClip("pen", 1);
     for(var i = 0; i < triangles_xml.length; i++){
          var attributes = triangles_xml[i].attributes;
          pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
          pen.moveTo(attributes.mx, attributes.my);
          for(var j = 1; j < 5; j++){
               pen.lineTo(attributes["x" + j], attributes["y" + j]);
          }
     }
}
data_xml.load("box.xml");

Works fine. It will create Box I need. How do I get them to work together.


I tried putting the box code in  triangles.xml with triangles, Its drawn but filled with color as its created over triangles, and takes up their links.

I tried creating another layer, and doing same thing with box, but only box gets displayed, no triangles.

Because coordinates will be dynamically generated, I need it to read new file lets say every 10 seconds.
valentin_vAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

negatyveCommented:
What's inside box.xml?
0
valentin_vAuthor Commented:
<?xml version="1.0" encoding="UTF-8"?>
<triangles>
     <item thickness="1" rgb="002040" alpha="100" mx="140" my="10"  x1="160" y1="10" x2="160" y2="100" x3="140" y3="100" x4="140" y4="10" />
     <item thickness="1" rgb="002040" alpha="100" mx="180" my="10"  x1="260" y1="10" x2="260" y2="100" x3="180" y3="100" x4="180" y4="10" />
</triangles>
0
negatyveCommented:
ok, only one xml file, "shapes.xml":

=================================================================
<?xml version="1.0" encoding="UTF-8"?>
<shapes>
      <triangles>
            <item
                  link="http://www.altavista.com/" target="_blank"
                  thickness="1" rgb="002040" alpha="100"
                  mx="100" my="130"
                  x1="358" y1="130"
                  x2="358" y2="260"
                  x3="100" y3="130" />
            <item
                  link="http://www.yahoo.com/" target="_self"
                  thickness="2" rgb="FFCC00" alpha="20"
                  mx="400" my="130"
                  x1="663" y1="130"
                  x2="400" y2="232"
                  x3="400" y3="130" />
      </triangles>
      <boxes>
            <item
                  thickness="1" rgb="002040" alpha="100"
                  mx="140" my="10"
                  x1="160" y1="10"
                  x2="160" y2="100"
                  x3="140" y3="100"
                  x4="140" y4="10" />
            <item
                  thickness="1" rgb="002040" alpha="100"
                  mx="180" my="10"
                  x1="260" y1="10"
                  x2="260" y2="100"
                  x3="180" y3="100"
                  x4="180" y4="10" />
      </boxes>
</shapes>
=================================================================


and only one movie, with this code:

=================================================================
data_xml = new XML();
data_xml.path = this;
data_xml.ignoreWhite = true;
data_xml.onLoad = function(ok)
{
      if (ok) {
            this.path.drawTriangles(this.firstChild.firstChild.childNodes);
            this.path.drawBoxes(this.firstChild.lastChild.childNodes);
      } else {
            trace("XML FILE NOT FOUND");
      }
};
function drawTriangles(triangles_xml)
{
      for (var i = 0; i < triangles_xml.length; i++) {
            var pen = this.createEmptyMovieClip("pen" + i, i);
            var attributes = triangles_xml[i].attributes;
            pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
            pen.moveTo(attributes.mx, attributes.my);
            pen.beginFill(parseInt(attributes.rgb, 16), attributes.alpha);
            for (var j = 1; j < 4; j++)pen.lineTo(attributes["x" + j], attributes["y" + j]);
            pen.endFill();
            pen.__target = attributes.target;
            pen.__link = attributes.link;
            pen.onRelease = function()
            {
                  this.getURL(this.__link, this.__target);
            };
      }
}
function drawBoxes(boxes_xml)
{
      for (var i = 0; i < boxes_xml.length; i++) {
            var pen = this.createEmptyMovieClip("pen" + i, i + 1000);
            var attributes = boxes_xml[i].attributes;
            pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
            pen.moveTo(attributes.mx, attributes.my);
            for (var j = 1; j < 5; j++)      pen.lineTo(attributes["x" + j], attributes["y" + j]);
      }
}
data_xml.load("shapes.xml");
=================================================================
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

valentin_vAuthor Commented:
How do I get it to refresh with new values taken from SHAPES.XML lets say every 5 seconds
0
negatyveCommented:
data_xml = new XML();
data_xml.path = this;
data_xml.ignoreWhite = true;
data_xml.onLoad = function(ok)
{
      if (ok) {
            this.triangles = this.firstChild.firstChild.childNodes;
            this.boxes = this.firstChild.lastChild.childNodes;
            this.path.drawTriangles();
            this.path.drawBoxes();
            clearInterval(this.loadID);
            this.loadID = setInterval(this, "updateData", 5000);
      } else {
            trace("XML FILE NOT FOUND");
      }
};
data_xml.updateData = function()
{
      var total = this.triangles.length + this.boxes.length;
      for(var i = 0; i < total; i++)this.path["pen" + i].removeMovieClip();
      delete this.triangles;      delete this.boxes;
      this.load("shapes.xml");
}
function drawTriangles()
{
      for (var i = 0; i < data_xml.triangles.length; i++) {
            var pen = this.createEmptyMovieClip("pen" + i, i);
            var attributes = data_xml.triangles[i].attributes;
            pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
            pen.moveTo(attributes.mx, attributes.my);
            pen.beginFill(parseInt(attributes.rgb, 16), attributes.alpha);
            for (var j = 1; j < 4; j++)pen.lineTo(attributes["x" + j], attributes["y" + j]);
            pen.endFill();
            pen.__target = attributes.target;      pen.__link = attributes.link;
            pen.onRelease = function()      {      this.getURL(this.__link, this.__target);      };
      }
}
function drawBoxes()
{
      var precs = data_xml.triangles.length;
      for (var i = precs; i < data_xml.boxes.length + precs; i++) {
            var pen = this.createEmptyMovieClip("pen" + i, i);
            var attributes = data_xml.boxes[i - precs].attributes;
            pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
            pen.moveTo(attributes.mx, attributes.my);
            for (var j = 1; j < 5; j++)      pen.lineTo(attributes["x" + j], attributes["y" + j]);
      }
}
data_xml.load("shapes.xml");
0
valentin_vAuthor Commented:
Works fine ok Computer but on the web files don;t updated. They get cached, so how to reload a file so It does not get cached by FLASH.

That would be the last problem to get fixed with this .

0
negatyveCommented:
Change this function:

data_xml.updateData = function()
{
    var total = this.triangles.length + this.boxes.length;
    for(var i = 0; i < total; i++)this.path["pen" + i].removeMovieClip();
    delete this.triangles;     delete this.boxes;
    this.load("shapes.xml");
}

to

data_xml.updateData = function()
{
    var total = this.triangles.length + this.boxes.length;
    for(var i = 0; i < total; i++)this.path["pen" + i].removeMovieClip();
    delete this.triangles;     delete this.boxes;
    this.load("shapes.xml?updated=" + (new Date().getTime()));
}
0
valentin_vAuthor Commented:
yOU THE BEST.

Sorry but only one more thing, Is there a way to split shapes.xml, into 2 files one for TRIANGLES, one for BOXES to keep them separate for easyer updating of values.

Thanks again, and this is for sure last thing
0
negatyveCommented:
boxes.xml


<?xml version="1.0" encoding="UTF-8"?>
<boxes>
      <item
            thickness="1" rgb="002040" alpha="100"
            mx="140" my="10"
            x1="160" y1="10"
            x2="160" y2="100"
            x3="140" y3="100"
            x4="140" y4="10" />
      <item
            thickness="1" rgb="002040" alpha="100"
            mx="180" my="10"
            x1="260" y1="10"
            x2="260" y2="100"
            x3="180" y3="100"
            x4="180" y4="10" />
</boxes>

=====================================================
=====================================================

triangles.xml

<?xml version="1.0" encoding="UTF-8"?>
<triangles>
      <item
            link="http://www.altavista.com/" target="_blank"
            thickness="1" rgb="002040" alpha="100"
            mx="100" my="130"
            x1="358" y1="130"
            x2="358" y2="260"
            x3="100" y3="130" />
      <item
            link="http://www.yahoo.com/" target="_self"
            thickness="2" rgb="FFCC00" alpha="20"
            mx="400" my="130"
            x1="663" y1="130"
            x2="400" y2="232"
            x3="400" y3="130" />
</triangles>


=====================================================
=====================================================

movie script:


triangles_xml = new XML();
triangles_xml.path = this;
triangles_xml.ignoreWhite = true;
triangles_xml.onLoad = function(ok)
{
      if (ok) {
            this.triangles = this.firstChild.childNodes;
            this.drawTriangles();
            clearInterval(this.loadID);
            this.loadID = setInterval(this, "updateData", 5000);
      } else {
            trace("XML FILE NOT FOUND");
      }
};
triangles_xml.updateData = function()
{
      for (var i = 0; i < this.triangles.length; i++)      this.path["tre" + i].removeMovieClip();
      delete this.triangles;
      this.load("triangles.xml");
};
triangles_xml.drawTriangles = function()
{
      for (var i = 0; i < this.triangles.length; i++){
            var pen = this.path.createEmptyMovieClip("tre" + i, i);
            var attributes = this.triangles[i].attributes;
            pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
            pen.moveTo(attributes.mx, attributes.my);
            pen.beginFill(parseInt(attributes.rgb, 16), attributes.alpha);
            for (var j = 1; j < 4; j++) {
                  pen.lineTo(attributes["x" + j], attributes["y" + j]);
            }
            pen.endFill();
            pen.__target = attributes.target;
            pen.__link = attributes.link;
            pen.onRelease = function()
            {
                  this.getURL(this.__link, this.__target);
            };
      }
}
triangles_xml.load("triangles.xml");

boxes_xml = new XML();
boxes_xml.path = this;
boxes_xml.ignoreWhite = true;
boxes_xml.onLoad = function(ok)
{
      if (ok) {
            this.boxes = this.firstChild.childNodes;
            this.drawBoxes();
            clearInterval(this.loadID);
            this.loadID = setInterval(this, "updateData", 5000);
      } else {
            trace("XML FILE NOT FOUND");
      }
};
boxes_xml.updateData = function()
{
      for (var i = 0; i < this.boxes.length; i++)      this.path["box" + i].removeMovieClip();
      delete this.boxes;
      this.load("boxes.xml");
};

boxes_xml.drawBoxes = function()
{
      for (var i = 0; i < this.boxes.length ; i++) {
            var pen = this.path.createEmptyMovieClip("box" + i, i + 1000);
            var attributes = this.boxes[i].attributes;
            pen.lineStyle(attributes.thickness, parseInt(attributes.rgb, 16), attributes.alpha);
            pen.moveTo(attributes.mx, attributes.my);
            for (var j = 1; j < 5; j++) {
                  pen.lineTo(attributes["x" + j], attributes["y" + j]);
            }
      }
}
boxes_xml.load("boxes.xml");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.