Results 1 to 9 of 9

Thread: Button Question

  1. #1
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Button Question

    Hello..

    hopefully someone can help.

    I have an animated menu with various buttons which all have up states and down states, I want to be able to change the buttons paths from outside Flash, is there a way to do this? I know xml can achieve this but I dont really want to create a new xml menu... unless I can apply xml to the buttons I have already?

    Can anyone please help or point me in the right direction?

    Thanks in advance!

    Hurley

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    You can indeed add button paths via XML to already created buttons. I'm assuming you're pointing to external sources (i.e. not linking within the flash itself).

    Create an XML like so:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <navigation>
        <button link="http://www.dynamicdrive.com" />
        <button link="http://www.dynamicdrive.com" />
        <button link="http://www.dynamicdrive.com" />
        <button link="http://www.dynamicdrive.com" />
    </navigation>
    Add this AS to your Flash navigation:
    Code:
    var xml:XML = new XML()
    xml.ignorewhite = true;
    
    xml.onLoad = function (success) {
       if (success) {
           parent = this.firstChild
           loadPaths();
       }
    }
    
    xml.load("filename.xml")
    
    function loadPaths();
         for (i=0;i<parent.length;i++) {
             var btnClip = eval ("btn" + i)
             var btnPath = parent.childNodes[i].attributes.link
    
             btnClip.onRelease = function() {
                 getURL(btnPath)
             }
          }
    }
    For this to work, all your buttons should be named "btn#" starting with "btn0"

    Warning: this was typed directly into the browser so there might be typos.

  3. #3
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ill explain my problem in more depth...

    I have a button created in a movieclip which when clicked slides down another movie where a mediaDisplay componet (instance name myVideo) is housed to play an FLV. I modified the url to play the appropriate external flv video and it works fine but what I would like is to make the the contentPath to the video in an xml file. That means when I modify the external xml file the video housed in the mediaDisplay component changes to the new updated video.

    is this possible? Are there any good tutorial on this?

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    It is possible.

    The way to do it is just as I described above. It's just a matter of where you call the varaibles loaded by the XML.

    If you can upload your source files, I can help you further with that.

  5. #5
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have attached a sample file to this post Medyman.

    Im just looking how to make the contentPath of the video external (in the showreel.xml) So when button1 is clicked the video plays in the mediaDisplay component... I have not included any video because of the attachment size. Hopefully what I have encluded will be enough for you to demonstrate the technique. Thanks for your help much appreciated!!

    Thanks

    Hurley

  6. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hey Hurley,

    Can you include the actual .fla?

    By the way, if you're looking for a tutorial, Lee Brimelow has some amazing video tuts over at www.gotoAndLearn.com/download.php (scroll to the bottom of the list).

  7. #7
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi Medyman,

    Im unable to attach the fla due to attachment size limitations. Would it be possible for you to show me the technique by modifyin the code you posted before? You have the showreels xml file already which should show you the layout of my xml file and my fla file just consisted of 2 buttons (instance names "btn0, bt1") and a mediaDisplay component (instance name "myVideo").

    So to run through the scenario again...

    When btn0 is clicked it loads an flv into the mediaDisplay component instance name "myVideo"... path to vid can be changed through the xml file.

    When btn1 is clicked it stops the previous flv (if its playing) and loads in the next flv into the myVideo mediaDisplay... again path to vid can be changed through external xml file.

    really appreciate your help Medyman... thanks!

  8. #8
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok Medyman ... I think I got it working... kinda... I used this code...

    Keyframe actions

    var contextXML:XML = new XML();
    contextXML.ignoreWhite = true;
    contextXML.load('video.xml');
    contextXML.onLoad = function(success){
    if (success){
    sVideoPath = this.firstChild.childNodes[0].attributes.url;
    }
    }

    and on the button

    on (release) {

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);

    theVideo.attachVideo(ns);

    ns.play(sVideoPath);

    }

    my XML

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <movies>
    <movie url="videos/video1.flv" />
    <movie url="videos/video2.flv" />
    </movies>


    I got it so the video plays on release of button 1 but do you know how I could differentiate between buttons? What code I could add to the other button so it plays the next line (video2) in the xml? I think its nearly there.

    Hurley

  9. #9
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Ok...

    For starters, I would get out of the habit of putting button actions on the buttons themeselves. When you're trying to do something of this nature, I would keep all actions on a dedicated, locked actions layer.

    Since you're trying to call all your buttons with 1 code, this makes it a lot easier.


    Next, change all your button instances names to ns0, ns1, ns2....and so on. This will make the coding easier to call with a for loop.

    In youf xml.onLoad function, you're declaring a variable that's hardcoded for the first node. We want to use a for loop so that the node value (childNodes9[nodevalue]) cooresponds to each button.

    So, we want node[0] to link to ns0, node[1] to link to ns1 and so on. **Remember that XML documents start counting at 0.**


    Now to the as (all on the timeline):
    Code:
    var contextXML:XML = new XML();
    contextXML.ignoreWhite = true;
    contextXML.load('video.xml');
    
    contextXML.onLoad = function(success){
       if (success)  {
          parent = this.firstChild        //makes the syntax a bit easier
          maxNodes = parent.length
          loadLinks();  // a function we'll construct to parse the XML
       }
    }
    
    
    function loadLinks() {
       for (i=0,i<maxNodes,i++) {
          var tmpClip:MovieClip = eval ("ns" + i)  //evaluates each ns movieclip
          tmpClip.id = i
    
          tmpClip.onRelease = function() {
             var nc:NetConnection = new NetConnection();
             nc.connect(null);
    
             var ns:NetStream = new NetStream(nc);
    
             theVideo.attachVideo(ns);
             ns.play(parent.childNodes[this.id].attributes.url);
    
    }

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
  •