Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-26-2009, 11:11 PM   #1
billcoons
Registered User
 
Join Date: Jan 2006
Posts: 6
Default AS3 / XML issues

I'm a designer trying to learn AS3, so please bear with me...

I'm creating a new portfolio site with Flash/AS3 and XML so when I want to add new examples, I only have to touch the XML file. Basically, I'm creating some buttons dynamically through XML. That part i've figured out. What I need to do, depending on which of those dynamically buttons is clicked, I want to also pull the project title (title attribute in the XML).

Here's the XML:

<?xml version="1.0" encoding="utf-8"?>

<site>
<links>
<link name="1" title="Project 1" />
<link name="2" title="Project 2" />
<link name="3" title="Project 3" />
<link name="4" title="Project 4" />
</links>
</site>

Here's the AS:

import fl.transitions.Tween;
import fl.transitions.easing.*;

var xmlPath:String = "data/identity.xml";
var settingsXML:XML;

var loader = new URLLoader();
loader.load (new URLRequest(xmlPath));
loader.addEventListener (Event.COMPLETE, xmlLoaded);

function xmlLoaded (e:Event):void {

if ((e.target as URLLoader) != null ) {
settingsXML = new XML(loader.data);
settingsXML.ignoreWhitespace = true;
createMenu ();
}

}

function createMenu ():void {
var menuItem:MenuItem;

var i:uint = 0;
for each (var link:XML in settingsXML.links.link) {
menuItem = new MenuItem();

menuItem.menuLabel.text = link.@name;
menuItem.name = "project" + menuItem.menuLabel.text;

menuItem.menuLabel.autoSize = TextFieldAutoSize.CENTER;

menuItem.x = -200;
menuItem.y = -100 + i*60;

menuItem.buttonMode = true;
menuItem.mouseChildren = false;

menuItem.addEventListener (MouseEvent.CLICK, mouseClicked);

addChild (menuItem);
i++;
}
}

function mouseClicked(e:Event):void {
trace(e.target.name);
}

I've tried several different approaches in the mouseClicked function, but I can't anything to work. Suggestions please?

Thanks,
Bill
billcoons is offline   Reply With Quote
Old 10-27-2009, 12:57 AM   #2
krayzeebean
Senior Member
 
Join Date: Feb 2006
Posts: 377
Default

In your MenuItem class, add a public var (it should be a string) to hold the title. Then in your loop, add the line
ActionScript Code:
menuItem.title = link.@title;

In your mouseClicked function:
ActionScript Code:
trace(e.target.title);
krayzeebean is offline   Reply With Quote
Old 10-27-2009, 01:24 AM   #3
billcoons
Registered User
 
Join Date: Jan 2006
Posts: 6
Default

Oh man! Thanks soooo much!! I knew it was something simple that I was missing.
billcoons is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:42 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.