Solved

Import ActionScripts from another file

Posted on 2003-11-05
5
234 Views
Last Modified: 2010-04-03
I need to be able to draw a triangle from coordinated taken from txt file

This is example that should be in txt file, or is there any other format that can be used for X, Y, values to be taken from.

_root.createEmptyMovieClip("pen", 1);
pen.lineStyle(1, 0x002040, 100);
pen.moveTo(100, 130);
pen.lineTo(358, 130);
pen.lineTo(358, 260);
pen.lineTo(100, 130);
pen.lineStyle(2, 0x000000, 100);
pen.moveTo(400, 130);
pen.lineTo(663, 130);
pen.lineTo(400, 232);
pen.lineTo(400, 130);

What I need is a format in txt  file to be imported and to do same result as the one above. I will be getting coordinates for triangle 6 of them at the time, and I need way to import those coordinates to draw 6 triagles.

So when these triangles are drawn, I need to be able to click on them to show a little more info that would be impoted from another txt file.

Thanks,

Valentin
0
Comment
Question by:valentin_v
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:negatyve
Comment Utility
Create an xml file like this:

<?xml version="1.0" encoding="UTF-8"?>
<triangles>
      <item thickness="1" rgb="002040" alpha="100" mx="100" my="130"      x1="358" y1="130" x2="358" y2="260" x3="100" y3="130" />
      <item thickness="2" rgb="FFCC00" alpha="20"  mx="400" my="130"  x1="663" y1="130" x2="400" y2="232" x3="400" y3="130" />
</triangles>

then create, in the same folder, a flash 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.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 < 4; j++){
                  pen.lineTo(attributes["x" + j], attributes["y" + j]);
            }
      }
}
data_xml.load("triangles.xml");
0
 
LVL 5

Expert Comment

by:Calron
Comment Utility
This is a tutorial on how to read from a textfile:

http://www.flashkit.com/tutorials/Actionscripting/Basic/Reading_-Brett_Ta-139/index.php


read through that. For a triangle your textfile could look like this:

&x1=100&y1=100&x2=200&y2=200&x3=300&y3=230&
0
 

Author Comment

by:valentin_v
Comment Utility
OK, How to have each triangle as a button so when triangle is displayed it should be clickable to sho more info about triangle.
0
 
LVL 27

Accepted Solution

by:
negatyve earned 125 total points
Comment Utility
Change your xml file to:

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

And change your script to:

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)
{
      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);
            };
      }
}
data_xml.load("triangles.xml");
0
 

Author Comment

by:valentin_v
Comment Utility
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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
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.

772 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

15 Experts available now in Live!

Get 1:1 Help Now