Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Create clickable lines based on XML data

    Hey,

    i am noob when it comes to action scripting.

    My goal
    ===========
    To have a map of the world (image i already have) in the background and onLoad to read in an xml file that contains points of from and to locations of a line. When the line is created, you should be able to click it and get information (form the xml file)

    Done so Far
    ===========
    I have the map in the background. The next layer above it has the code for reading in xml:

    Reading the xml data
    ---------------------
    xmldata = new XML();
    xmldata.load("data.xml");
    xmldata.ignoreWhite = true;
    xmldata.onLoad=extractData;

    function extractData(success){
    rootHandler=this.firstChild.childNodes; // First level - <channel>
    nodeHandler=rootHandler[0].childNodes; // Second level
    source=nodeHandler[1].firstChild.nodeValue;
    //trace(source);
    }

    XML file
    ---------------------
    <?xml version="1.0" encoding="utf-8"?>
    <Data>
    <DocumentProperties>
    <Title>TEST</Title>
    </DocumentProperties>
    <Connections>
    <Connection ID="1" Name="TEST Line Connection">
    <Coordinates>
    <From>
    <X>0</X>
    <Y>100</Y>
    </From>
    <To>
    <X>100</X>
    <Y>100</Y>
    </To>
    </Coordinates>
    <Value>test1</Value>
    <Label>Test Line Item #1</Label>
    </Connection>
    </Connections>
    </Data>

    Creating the line
    ---------------------
    createEmptyMovieClip("Line",1);
    Line.lineStyle(1,0x000000,100);
    line1.onPress = function()
    {
    trace("This is line #1");
    }

    Need to Do
    =================
    Create the From points of a line from the xml data and creating a line to the To points. When that line is created, have some type of reference so when it is clicked, I can look up the line representation of that line. I know I have to use Line.moveTo(x,y); and Line.lineTo(x, y); Just not sure how. Also is these lines being created have to be converted to a movie or graphic, or can I live it as something else?

    Thanx
    =================
    Any and all help is appreciated. Thank you.

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,


    I'm not very clear on what your trying to achieve, but it sounds like something from one destination to another on a map. The drawing API can be used on the main timeline or inside a movieclip. If used inside a movieclip, you have more control as you can manipulate the holder movieclips properties. The lineTo method can also be used in conjuction with movieclips and not be a movieclip object. Here is a function for dynamically drawing a line between two movieclips. This might be useful for drawing a line from a starting destination movieclip to an ending destination movieclip. It currently allows for the clips to be dragged and the line auto updates, but you could refine that to suit your needs...

    Code:
    function makeLine&#40;name, depth, lineSize, color, alpha, posA, posB&#41; &#123;
    	this.createEmptyMovieClip&#40;name, depth&#41;;
    	with &#40;this&#91;name&#93;&#41; &#123;
    		lineStyle&#40;lineSize, color, alpha&#41;;
    		moveTo&#40;_root&#91;posA&#93;._x, _root&#91;posA&#93;._y&#41;;
    		lineTo&#40;_root&#91;posB&#93;._x, _root&#91;posB&#93;._y&#41;;
    	&#125;
    &#125;
    _root.onEnterFrame = function&#40;&#41; &#123;
    	makeLine&#40;"line", 1, 2, "0xFF0000", 100, "mc1", "mc2"&#41;;
    &#125;
    _root.MC2.onPress = function&#40;&#41; &#123;
    	startDrag&#40;"MC2"&#41;;
    &#125;
    _root.MC2.onRelease = function&#40;&#41; &#123;
    	stopDrag&#40;&#41;;
    &#125;
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  4. #3

    Default

    thnx for the response

    My goal in simplest form is to create a line from pointA to pointB and onPress, shows some text (multiple lines, lineA, lineB, lineC,...)

    i still got a few questions:

    1) on (_root.MC2.onPress) - why are u using MC2? shouldn't I be using the name of the line?

    2) Where do I put this code? on what layer? what frame?

    3) I don't need to drag - just show text (example: clicking on line#1 shows "hi, i am lineA")

    4) Is my xml code correct?

    5) My idea was to have only 1 Frame that loads all of the lines from different points (a and b) and display it on the screen. Then onclick of that newly created line, show text (I just don't know if that should be sent to another frame or just another function in that the first frame)

    just a note:

    I changed posA to posAX and posAY (as in coordinates for the beginning of the line) and the same thing for

  5. #4
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    To understand what that code is doing, create a test movie with two movieclips with instance names of "mc1" and "mc2". Paste that code onto the first frame of the main timeline. The line is drawn in an enterFrame event between the two movieclips. The MC2 clip has a drag code only for demo purposes to show the line will update position no matter where the clip is dragged. You can disable that by removing the startdrag and stopdrag code but the guts of the function is to draw a line between any two points. This could be extended to work with more than two movieclips or could be used multiple times to draw lines between several groups of two movieclips to simulate a starting point and a destination point. If your looking to click on the actual line, another option is to create a movieclip holder and draw the line inside that clip. The clip itself could serve as the event handler. The XML code appears to be correct, but I am not especially well versed in XML and it usually takes me some testing to make sure everything is working as expected, but how it is set up using the XML object to handle the load appears correct.
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Web-based training assessment
    By brianmaysguitar in forum Newbies
    Replies: 3
    Last Post: 12-11-2006, 09:29 PM
  2. Lines Around Embedded SWF
    By ziola111 in forum Newbies
    Replies: 1
    Last Post: 05-16-2006, 01:26 PM
  3. huge slideshow based on xml
    By gondwana in forum Advanced Flash
    Replies: 2
    Last Post: 03-29-2006, 08:00 AM
  4. Replies: 1
    Last Post: 10-28-2005, 11:24 AM
  5. Spacing in Text button non-clickable
    By jonblazn in forum Newbies
    Replies: 1
    Last Post: 08-28-2005, 02:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial