Solved

Import ActionScripts from another file

Posted on 2003-11-05
5
236 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
ID: 9687227
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
ID: 9687255
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
ID: 9693768
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
ID: 9694229
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
ID: 9715758
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

910 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

25 Experts available now in Live!

Get 1:1 Help Now