Solved

Import ActionScripts from another file

Posted on 2003-11-10
9
306 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
  • 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to record live broadcast.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now