Flash menu from xml, making links

  • Mrc1n4
  • Novice
  • Novice
  • Mrc1n4
  • Posts: 26
  • Loc: Slovenia

Post 3+ Months Ago

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
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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: [ 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. }
  • Mrc1n4
  • Novice
  • Novice
  • Mrc1n4
  • Posts: 26
  • Loc: Slovenia

Post 3+ Months Ago

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
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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
  • Mrc1n4
  • Novice
  • Novice
  • Mrc1n4
  • Posts: 26
  • Loc: Slovenia

Post 3+ Months Ago

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
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

probably you didnt name the instances of the movie clips. i'll take a look over your fla to see.
  • Mrc1n4
  • Novice
  • Novice
  • Mrc1n4
  • Posts: 26
  • Loc: Slovenia

Post 3+ Months Ago

No, I named them right I think... Did u check my .fla?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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.
  • Mrc1n4
  • Novice
  • Novice
  • Mrc1n4
  • Posts: 26
  • Loc: Slovenia

Post 3+ Months Ago

Here is mx2004, but I think it's no use for u?
click
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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)
  • Mrc1n4
  • Novice
  • Novice
  • Mrc1n4
  • Posts: 26
  • Loc: Slovenia

Post 3+ Months Ago

oh thank you m8... Now works fine :)
  • Craiggiej
  • Born
  • Born
  • Craiggiej
  • Posts: 3

Post 3+ Months Ago

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
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

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.
  • Craiggiej
  • Born
  • Born
  • Craiggiej
  • Posts: 3

Post 3+ Months Ago

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: [ 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 10 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.