Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic XML menu with links that perform functions...getting desperate

Explorer ,
Jun 27, 2008 Jun 27, 2008
I'm trying to create a simple dynamic menu generated from a XML file. I have my XML file set up correctly, I can load the XML successfully and read the data in Flash, I can even generate the buttons successfully. The part I'm really struggling with is having the buttons perform different functions within Flash when clicked.

Basically what I want to do is create a simple portfolio viewer. When a button is clicked, the corresponding image and caption text will load (also defined in the XML file). The closest thing I've found is the tutorial here...
http://www.flashdev.ca/article/building-a-basic-menu-in-actionscript-30-tutorial-part-2-xml/

Its simple and basically does what I want it to do. But at the end, when a button is clicked, I'm not sure how to get that function to read the XML data associated with the button clicked, and then load that data. That way I can use the data to load the image and fill the dynamic text box with the caption text. Thanks for any help, and I don't even need specific code, just a little push. I like to try and figure these things out on my own, but this has me stalled for a few days.

code from tutorial link...

TOPICS
ActionScript
592
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 27, 2008 Jun 27, 2008
Hi Mike,
Vikings fan or declaration of heritage?
Anyway, I'm not sure I follow exactly what you're after, but I just watched a really good tutorial dealing with importing XML files to make a simple RSS feed reader. It's probably not what you're looking for, but might spark something and send you in the right direction. At the very least, it creates a dynamic menu that changes the value of a text box based on what you click. It's worth a watch anyway, if you're dealing with XML for my $0.02.

AS3 Intro to XML

Hope it helps,
SyddyS
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 27, 2008 Jun 27, 2008
quote:

Originally posted by: SyddyS
Hi Mike,
Vikings fan or declaration of heritage?
Anyway, I'm not sure I follow exactly what you're after, but I just watched a really good tutorial dealing with importing XML files to make a simple RSS feed reader. It's probably not what you're looking for, but might spark something and send you in the right direction. At the very least, it creates a dynamic menu that changes the value of a text box based on what you click. It's worth a watch anyway, if you're dealing with XML for my $0.02.

AS3 Intro to XML

Hope it helps,
SyddyS


Actually how my name came about is a little weird. When I was a kid, I would check out drawing books from the library by Lee J. Ames. He had series, like "How to Draw Insects", "How to Draw Monsters", etc. I loved the books. One character in the monsters book was a viking named Mike the Vike. Sicne i was young, I thoguht it was so cool that it was named after me. Then when the internet came around, and I had to start using an online alias, I chose that and have stuck with it for years, haha

I actually have already seen that tutorial. great tutorial and great site, but doesn't help me with the problem I'm having.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 27, 2008 Jun 27, 2008
I think your situation is that you would like an arbitary number of buttons to share the same event handler. So you ideally you would like to pass a parameter to the event handler. I found this handy article,

http://wildwinter.blogspot.com/2007/04/come-back-delegate-all-is-forgiven.html

Once you get the callback class into your classpath or same directory as your fla and import it. You can make calls like this.

button1.addEventListener(MouseEvent.CLICK,Callback.create(onButtonPressed,1));
button1.addEventListener(MouseEvent.CLICK,Callback.create(onButtonPressed,2));

passing the values 1 or 2 to the same handler so you know which button sent it. Alternatively send some string from the xml.

private function onButtonPress(event:MouseEvent,num:Number):void
{
trace("Button "+num+" has been pressed!");
}

Hope this helps
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 27, 2008 Jun 27, 2008
LATEST
quote:

Originally posted by: charlie656
I think your situation is that you would like an arbitary number of buttons to share the same event handler. So you ideally you would like to pass a parameter to the event handler. I found this handy article,



Thats exactly what I want to do. dynamic number of buttons sharing the same event listener. I took a look at the link, sounds like it might be close to what I need to make it work. Some of the comments on there make it seem like this should be easier to do using event.target, but I'm not really sure how to implement that and pass a number to the onButtonPress function...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines