Solved

Import ActionScripts from another file

Posted on 2003-11-05
5
239 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
[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
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

688 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