?
Solved

Import ActionScripts from another file

Posted on 2003-11-10
9
Medium Priority
?
321 Views
Last Modified: 2010-04-03
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.
0
Comment
Question by:valentin_v
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 9717276
What's inside box.xml?
0
 

Author Comment

by:valentin_v
ID: 9717531
<?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
 
LVL 27

Expert Comment

by:negatyve
ID: 9717642
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:valentin_v
ID: 9721948
How do I get it to refresh with new values taken from SHAPES.XML lets say every 5 seconds
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9722026
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
 

Author Comment

by:valentin_v
ID: 9722091
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
 
LVL 27

Expert Comment

by:negatyve
ID: 9722102
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
 

Author Comment

by:valentin_v
ID: 9722159
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
 
LVL 27

Accepted Solution

by:
negatyve earned 2000 total points
ID: 9725209
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question