XML new line?

  • cooper10
  • Born
  • Born
  • cooper10
  • Posts: 3

Post 3+ Months Ago

XML new line?

Hi all,

I have a simple vertical nav menu by attaching MC's using an XML file. The names on the MC's come from the name attribute in the XML file, so the names read 'First Button', 'Second Button' etc., is it possible to put a line break in so it would read

First
Button

Second
Button etc.

instead of

First Button

Second Button

XML file
Code: [ Select ]
<cart>
    <btn name="First Button" color="0xffcc00" />
    <btn name="Second Button" color="0xffcc00" />
    <btn name="Third Button" color="0xffcc00" />
    <btn name="Fifth Button" color="0xffcc00" />
    <btn name="Sixth Button" color="0xffcc00" />
</cart>
  1. <cart>
  2.     <btn name="First Button" color="0xffcc00" />
  3.     <btn name="Second Button" color="0xffcc00" />
  4.     <btn name="Third Button" color="0xffcc00" />
  5.     <btn name="Fifth Button" color="0xffcc00" />
  6.     <btn name="Sixth Button" color="0xffcc00" />
  7. </cart>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

http://www.sephiroth.it/proto_detail.php?id=16

I can't believe Flash still doesn't have a String.replace method built in.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

probably they ment it as a learn how to do it function :P
  • northstjarna
  • Beginner
  • Beginner
  • northstjarna
  • Posts: 58
  • Loc: Chertsey, UK

Post 3+ Months Ago

hi there,

create your button swf with dynamic text and make sure export for actionscript is checked.
after loading in your xml create an attach .swf mehtod with a variable of the Y position of each instance in a loop. - I can't garuntee this code will work first time for you so put traces on tjhe arrays and amend them as necessary.

this bit goes in frame 1

Code: [ Select ]

///ignore the whitespace always best
XML.prototype.ignoreWhite = true;

///Create a new empty XML Object
var myXMLbuttons:XML = new XML();

///load in the xml files
myXMLbuttons.load("xml/buttons.xml");           // xml source for your buttons
myXMLbuttons.onLoad = function(success){       //open function statement (1)
var rootNode:XMLNode = myXMLCoreTeam.firstChild;
var contentNode:XMLNode = rootNode.firstChild;

//new array for the total number of childNodes
    _global.menuArray = new Array();    
    _global.menuArray = rootNode.childNodes;
    
    _global.numOfItems = _global.menuArray.length;
    _global.buttontext = new Array();
    _global.buttonURL = new Array();
    
//set up Arrays for each attribute of each child
        for(var i=0;i<=_global.numOfItems;i++){ // (2) For loop -

//depending on how your xml is set up you will need to load in as attributes or nodes (omit one lot of comments)

        //_global.buttontrxt.push(menuArray[i].childNodes[0].childNodes[0].nodeValue);
        //_global.buttonURL.push(menuArray[i].childNodes[1].childNodes[0].nodeValue);
        
//or chose to load in as attributes

     //_global.buttontext.push(this.firstChild.childNodes[i].attributes.BUTTONName);
     //_global.buttonURL.pushpush(this.firstChild.childNodes[i].attributes.BUTTONurl);
            
    

        } //Close Loop    (2)
    
    
    gotoAndPlay("success");   /// if sucessful goto and play another frame where it makes the buttons

} //Close function (1)
  1. ///ignore the whitespace always best
  2. XML.prototype.ignoreWhite = true;
  3. ///Create a new empty XML Object
  4. var myXMLbuttons:XML = new XML();
  5. ///load in the xml files
  6. myXMLbuttons.load("xml/buttons.xml");           // xml source for your buttons
  7. myXMLbuttons.onLoad = function(success){       //open function statement (1)
  8. var rootNode:XMLNode = myXMLCoreTeam.firstChild;
  9. var contentNode:XMLNode = rootNode.firstChild;
  10. //new array for the total number of childNodes
  11.     _global.menuArray = new Array();    
  12.     _global.menuArray = rootNode.childNodes;
  13.     
  14.     _global.numOfItems = _global.menuArray.length;
  15.     _global.buttontext = new Array();
  16.     _global.buttonURL = new Array();
  17.     
  18. //set up Arrays for each attribute of each child
  19.         for(var i=0;i<=_global.numOfItems;i++){ // (2) For loop -
  20. //depending on how your xml is set up you will need to load in as attributes or nodes (omit one lot of comments)
  21.         //_global.buttontrxt.push(menuArray[i].childNodes[0].childNodes[0].nodeValue);
  22.         //_global.buttonURL.push(menuArray[i].childNodes[1].childNodes[0].nodeValue);
  23.         
  24. //or chose to load in as attributes
  25.      //_global.buttontext.push(this.firstChild.childNodes[i].attributes.BUTTONName);
  26.      //_global.buttonURL.pushpush(this.firstChild.childNodes[i].attributes.BUTTONurl);
  27.             
  28.     
  29.         } //Close Loop    (2)
  30.     
  31.     
  32.     gotoAndPlay("success");   /// if sucessful goto and play another frame where it makes the buttons
  33. } //Close function (1)


ok after successfully loading we are going to create a new instance of each button mc on stage and assign each new instance a new ylocation

do this on frame labelled success...


Code: [ Select ]
        
////////////////////////////////////// Function for creating buttons //////////////////////////////////////

_global.Heightofbutton = 100;
pushoverY = 0;

while(L<_global.numOfItems){//open loop (1)
        this.attachMovie("button_mc", "button_mc" + L, (-L) , {_x:0 ,_y:pushoverY});
        set("button_mc" + L + ".menuID" , L);
    
            
    with (eval("button_mc" + L )){
        button_txt = _global.team_member_name[L];  //where button_txt is the name of the variable in the button
        
                
    }// end with evaluation    
            

        pushoverY = pushoverY + _global.Heightofbutton;
L=L+1;

} // closes loop (1)        
  1.         
  2. ////////////////////////////////////// Function for creating buttons //////////////////////////////////////
  3. _global.Heightofbutton = 100;
  4. pushoverY = 0;
  5. while(L<_global.numOfItems){//open loop (1)
  6.         this.attachMovie("button_mc", "button_mc" + L, (-L) , {_x:0 ,_y:pushoverY});
  7.         set("button_mc" + L + ".menuID" , L);
  8.     
  9.             
  10.     with (eval("button_mc" + L )){
  11.         button_txt = _global.team_member_name[L];  //where button_txt is the name of the variable in the button
  12.         
  13.                 
  14.     }// end with evaluation    
  15.             
  16.         pushoverY = pushoverY + _global.Heightofbutton;
  17. L=L+1;
  18. } // closes loop (1)        



ok the next thing is to assing some action script to your instance of your button. open/edit you button mc in the library


creat a new layer and create a box, convert to button but only assign it a hit area.
give the hit area an instance name of hitarea
next create a new layer for actionscript


Code: [ Select ]

LinkB= buttonURL[menuID]; //Link Value for Sub Menu - we assigned the menuID for each instance ni success on the main time line, buttonURL is the value from the xml file

buttonInstance._alpha = 100;

hitarea.onRollOver = function(){
buttonInstance._alpha = 50;
    
}

hitarea.onRollOut = function(){
buttonInstance._alpha = 100;

}

hitarea.onRelease = function(){
        getURL(LinkB, "_blank");
        //trace(LinkB);
}
  1. LinkB= buttonURL[menuID]; //Link Value for Sub Menu - we assigned the menuID for each instance ni success on the main time line, buttonURL is the value from the xml file
  2. buttonInstance._alpha = 100;
  3. hitarea.onRollOver = function(){
  4. buttonInstance._alpha = 50;
  5.     
  6. }
  7. hitarea.onRollOut = function(){
  8. buttonInstance._alpha = 100;
  9. }
  10. hitarea.onRelease = function(){
  11.         getURL(LinkB, "_blank");
  12.         //trace(LinkB);
  13. }

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 11 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.