[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Import ActionScripts from another file

Posted on 2003-11-05
5
Medium Priority
?
242 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
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 select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

656 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