Solved

Import ActionScripts from another file

Posted on 2003-11-05
5
238 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.

739 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