4 Replies Latest reply on Jul 12, 2008 7:16 PM by strayhand

    Updating vIewstack from dynamic buttons via actionscript

    strayhand
      Does anyone have a clear example of how to update a Viewstack index from a MOUSE_OVER event triggered from a button that's dynamically generated? It's kicking my butt.

      I have a viewstack component to the left (containing images), and a vbox component to the right (containing buttons). Both the viewstack and the buttons are generated dynamically from an XML file. I want to be able to assign an event handler to the button's MOUSE_OVER so that it changes the current viewstack index. There are several examples showing how to do this with actionscript that's written inline on buttons that are hardcoded. However my buttons are being generated once the XML script is loaded and for some reason I cannot successfully get the viewstack to update.

      When I try to use viewstack.selectedChild = name I get a 1067 error telling me that I cannot assign a string to a container. And when I try to use viewstack.selectedIndex = id the swf file freezes.

      Any insight into my problem would be appreciated. Thanks.
        • 2. Re: Updating vIewstack from dynamic buttons via actionscript
          strayhand Level 1
          G.

          Thanks for your post. I've been hacking away at this and I've got the following working:

          1. Automatically rotates through the viewstack
          2. Changes viewstack index based on mouse over/out events
          3. Stops the rotation on mouse over events
          4. Starts the rotation on mouse out events

          So now I'm left with one problem to fix:

          1. Changing the button states so that they hover as it's rotating through the viewstack.


          If you remember this is the same issue that I was struggling with in an earlier post. Your previous solution was to use the dispatchEvent method and to assign a new event to the button but I'm struggling to get it to work correctly. Here's my code. Take a look at the buttonOver method to see where I'm at.

          Thank you for your help.
          • 4. Re: Updating vIewstack from dynamic buttons via actionscript
            strayhand Level 1
            G.

            Thanks again for the code. I gave it a try and thanks to your code I noticed a few things that I was doing wrong. Mainly I was trying to use MOUSE_OVER/MOUSE_OUT instead of ROLL_OVER/ROLL_OUT. I also came to the conclusion that trying to update the button states from events triggered by the images was a bad idea. So I created a method that when called changes all of the button states to ROLL_OUT and then adjust the current button to ROLL_OVER. I'm able to call this method from multiple locations and it seems to do the trick.

            Anyways... I would have been stuck with your help. So thanks. Here's a zip file of my project. This seems to work okay locally but I'm running into issues getting the XML file to load on my test server. I think it might be a crossdomain.xml issue. I'm going to try and resolve it on Monday. Aside from that I only have one quirk that's bothering me, when I move my cursor off a button it doesn't stay in the ROLL_OVER state of the current image. I'm gonna try and find a way to deal with this.

            Thanks.