Flash menu from xml, making links

  • Mrc1n4
  • Novice
  • Novice
  • No Avatar
  • Joined: Apr 04, 2006
  • Posts: 26
  • Loc: Slovenia
  • Status: Offline

Post October 21st, 2006, 4:43 am

Hello! Here is my question... I have an xml file with this code:


Quote:
<friends>
<friend url="http://www.friend1.com">George</friend>
<friend url="http://www.friend2.com">John</friend>
<friend url="http://www.friend3.com">Peter</friend>
<friend url="http://www.friend4.com">Michael</friend>
</friends>



And an actionscript code:


Quote:
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = parseXML;
myXML.load("friends.xml");

function parseXML()
{
text1.text = myXML.firstChild.childNodes[0].firstChild.nodeValue;
text2.text = myXML.firstChild.childNodes[1].firstChild.nodeValue;
text3.text = myXML.firstChild.childNodes[2].firstChild.nodeValue;
text4.text = myXML.firstChild.childNodes[3].firstChild.nodeValue;
}





How can I make links from XML working in actionscript?

Thank you for answers :D
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 21st, 2006, 4:43 am

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1241
  • Loc: Ro
  • Status: Offline

Post October 23rd, 2006, 4:16 am

first of all load it dynamically since you may want to add/remove items from the xml without changing code in the actionscript.
But, for this example, make text1 a movie clip (rename it first to txt, then select it on the stage, press F8 and make it movie clip), then give to the instance name (in the property panel): txt1;
then just duplicate txt1 till u have 4 mcs, name them txt2, txt3, txt4.
then:
Code: [ Download ] [ Select ]
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = parseXML;
myXML.load("friends.xml");

function parseXML()
{
text1.txt.text = myXML.firstChild.childNodes[0].firstChild.nodeValue;
text1.strURL = myXML.firstChild.childNodes[0].attributes.url;
text2.txt.text = myXML.firstChild.childNodes[1].firstChild.nodeValue;
text2.strURL = myXML.firstChild.childNodes[1].attributes.url;
text3.txt.text = myXML.firstChild.childNodes[2].firstChild.nodeValue;
text3.strURL = myXML.firstChild.childNodes[2].attributes.url;
text4.txt.text = myXML.firstChild.childNodes[3].firstChild.nodeValue;
text4.strURL = myXML.firstChild.childNodes[3].attributes.url;

text1.onPress = function()
{
  getURL(this.strURL);
}
text2.onPress = function()
{
  getURL(this.strURL);
}

text3.onPress = function()
{
  getURL(this.strURL);
}

text4.onPress = function()
{
  getURL(this.strURL);
}

}
  1. var myXML:XML = new XML();
  2. myXML.ignoreWhite = true;
  3. myXML.onLoad = parseXML;
  4. myXML.load("friends.xml");
  5. function parseXML()
  6. {
  7. text1.txt.text = myXML.firstChild.childNodes[0].firstChild.nodeValue;
  8. text1.strURL = myXML.firstChild.childNodes[0].attributes.url;
  9. text2.txt.text = myXML.firstChild.childNodes[1].firstChild.nodeValue;
  10. text2.strURL = myXML.firstChild.childNodes[1].attributes.url;
  11. text3.txt.text = myXML.firstChild.childNodes[2].firstChild.nodeValue;
  12. text3.strURL = myXML.firstChild.childNodes[2].attributes.url;
  13. text4.txt.text = myXML.firstChild.childNodes[3].firstChild.nodeValue;
  14. text4.strURL = myXML.firstChild.childNodes[3].attributes.url;
  15. text1.onPress = function()
  16. {
  17.   getURL(this.strURL);
  18. }
  19. text2.onPress = function()
  20. {
  21.   getURL(this.strURL);
  22. }
  23. text3.onPress = function()
  24. {
  25.   getURL(this.strURL);
  26. }
  27. text4.onPress = function()
  28. {
  29.   getURL(this.strURL);
  30. }
  31. }
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • Mrc1n4
  • Novice
  • Novice
  • No Avatar
  • Joined: Apr 04, 2006
  • Posts: 26
  • Loc: Slovenia
  • Status: Offline

Post October 23rd, 2006, 9:11 am

Hello! Thank you for your respond.


Now my links work, but the text is not showed in my dynamic text fields (in txt movieclip). It's just blank space, but I can click it. You tried it in flash and works for you?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1241
  • Loc: Ro
  • Status: Offline

Post October 23rd, 2006, 11:18 pm

embed font -> read dynamic and input font section.
or... for dynamic embed ... but u dont need this now, anyway it's for the rest of the users, in case they forgot dynamic font embed
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • Mrc1n4
  • Novice
  • Novice
  • No Avatar
  • Joined: Apr 04, 2006
  • Posts: 26
  • Loc: Slovenia
  • Status: Offline

Post October 24th, 2006, 5:36 am

Hello! I embedded font but still doesn't show... If I put dynamic txt direct into main scene it works, but if I put it in MC it doesn't.
Here is my .fla if u want to look at it:
download .rar
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1241
  • Loc: Ro
  • Status: Offline

Post October 24th, 2006, 7:08 am

probably you didnt name the instances of the movie clips. i'll take a look over your fla to see.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • Mrc1n4
  • Novice
  • Novice
  • No Avatar
  • Joined: Apr 04, 2006
  • Posts: 26
  • Loc: Slovenia
  • Status: Offline

Post October 25th, 2006, 1:13 pm

No, I named them right I think... Did u check my .fla?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1241
  • Loc: Ro
  • Status: Offline

Post October 25th, 2006, 9:48 pm

will do it later today ... in case i dont forget, since i have flash 8 only @ home.
if you can place the MX version then i can do it sooner.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • Mrc1n4
  • Novice
  • Novice
  • No Avatar
  • Joined: Apr 04, 2006
  • Posts: 26
  • Loc: Slovenia
  • Status: Offline

Post October 26th, 2006, 6:19 am

Here is mx2004, but I think it's no use for u?
click
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1241
  • Loc: Ro
  • Status: Offline

Post October 27th, 2006, 12:00 am

heh ... you have 2 problems
1) you didnt instance the text field inside text1, text2, text3 ...
for this, just double click txt movieclip from the library (or text1 from the scene), select the text field and name it's instance to: txt . The change will reflect in all others, since they are the instances of the same movieclip.
2) you didnt embed the font correctly. You indeed clicked Specify ranges ... but next you have to select a char set -> i suggest Basic Latin.
You can select more ranges if you keep Ctrl pressed and then press with the mouse on other items.
Also you can include other characters (only if needed), typing them in the Include these characters box. You will have to do this if some characters dont appear in the text (like $, %, # ... etc ... depends)
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • Mrc1n4
  • Novice
  • Novice
  • No Avatar
  • Joined: Apr 04, 2006
  • Posts: 26
  • Loc: Slovenia
  • Status: Offline

Post October 27th, 2006, 7:00 am

oh thank you m8... Now works fine :)
  • Craiggiej
  • Born
  • Born
  • No Avatar
  • Joined: Sep 20, 2007
  • Posts: 3
  • Status: Offline

Post September 20th, 2007, 7:39 pm

I'm just wondering....

IceCold,
In the above directions you advise to name the instances of each movie clip: txt1, txt2, txt3, and txt4... however, I don't see where you reference that in the actionscript. Can you tell me your reasoning behind that, or am I just missing it?

Thanks!
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 22959
  • Loc: Pittsburgh PA
  • Status: Offline

Post September 20th, 2007, 8:05 pm

that's because if you scroll up you'll see the action script code and it wasn't txt1, txt2, txt3, and txt4... It was text1, text2, text3, and text4... Spelling makes a world of difference.
"There's no place like 127.0.0.1 except for ::1."
Boasting Rights Sports Forum. Join our NFL pool and Premiership soccer pool today!
Get paid to write articles - www.associatedcontent.com
  • Craiggiej
  • Born
  • Born
  • No Avatar
  • Joined: Sep 20, 2007
  • Posts: 3
  • Status: Offline

Post September 21st, 2007, 4:23 am

To quote what i am referring to... perhaps they are mispelled. Can yhou confirm? Thanks!


But, for this example, make text1 a movie clip (rename it first to txt, then select it on the stage, press F8 and make it movie clip), then give to the instance name (in the property panel): txt1;
then just duplicate txt1 till u have 4 mcs, name them txt2, txt3, txt4.
then:
Code: [ Download ] [ Select ]
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = parseXML;
myXML.load("friends.xml");

function parseXML()
{
text1.txt.text = myXML.firstChild.childNodes[0].firstChild.nodeValue;
text1.strURL = myXML.firstChild.childNodes[0].attributes.url;
text2.txt.text = myXML.firstChild.childNodes[1].firstChild.nodeValue;
text2.strURL = myXML.firstChild.childNodes[1].attributes.url;
text3.txt.text = myXML.firstChild.childNodes[2].firstChild.nodeValue;
text3.strURL = myXML.firstChild.childNodes[2].attributes.url;
text4.txt.text = myXML.firstChild.childNodes[3].firstChild.nodeValue;
text4.strURL = myXML.firstChild.childNodes[3].attributes.url;

text1.onPress = function()
{
  getURL(this.strURL);
}
text2.onPress = function()
{
  getURL(this.strURL);
}

text3.onPress = function()
{
  getURL(this.strURL);
}

text4.onPress = function()
{
  getURL(this.strURL);
}

}
  1. var myXML:XML = new XML();
  2. myXML.ignoreWhite = true;
  3. myXML.onLoad = parseXML;
  4. myXML.load("friends.xml");
  5. function parseXML()
  6. {
  7. text1.txt.text = myXML.firstChild.childNodes[0].firstChild.nodeValue;
  8. text1.strURL = myXML.firstChild.childNodes[0].attributes.url;
  9. text2.txt.text = myXML.firstChild.childNodes[1].firstChild.nodeValue;
  10. text2.strURL = myXML.firstChild.childNodes[1].attributes.url;
  11. text3.txt.text = myXML.firstChild.childNodes[2].firstChild.nodeValue;
  12. text3.strURL = myXML.firstChild.childNodes[2].attributes.url;
  13. text4.txt.text = myXML.firstChild.childNodes[3].firstChild.nodeValue;
  14. text4.strURL = myXML.firstChild.childNodes[3].attributes.url;
  15. text1.onPress = function()
  16. {
  17.   getURL(this.strURL);
  18. }
  19. text2.onPress = function()
  20. {
  21.   getURL(this.strURL);
  22. }
  23. text3.onPress = function()
  24. {
  25.   getURL(this.strURL);
  26. }
  27. text4.onPress = function()
  28. {
  29.   getURL(this.strURL);
  30. }
  31. }
[/quote]

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 90 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2010 Unmelted, LLC. Driven by phpBB © 2010 phpBB Group.