Solved

dynamic button

Posted on 2004-04-28
12
150 Views
Last Modified: 2010-04-03
i want to make some buttons in flash.
i want to take the link and the text under the buttons from an external file. how do i do that ?
0
Comment
Question by:pdd
  • 7
  • 5
12 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 10937764
hello, you need to make your buttons movieclips, then use loadVars to load text files.

the links, are they normal getURL's or different things?
0
 
LVL 4

Author Comment

by:pdd
ID: 10937827
i do not know how to do that. can you provide a fla file or something ?
0
 
LVL 4

Author Comment

by:pdd
ID: 10939654
till nowihave this

meniu.fla
Code:

date_meniu_file = "meniu.xml";
date_meniu = new XML(date_meniu_file);
date_meniu.load(date_meniu_file);
date_meniu.ignoreWhite = true;
for (i=0; i<date_meniu.firstChild.childNodes.length; i++) {
   txt += String(date_meniu.childNodes[i].attributes['text']);
   url += String(date_meniu.childNodes[i].attributes['url']);
   trg += String(date_meniu.childNodes[i].attributes['target']);
}
rand1.text = txt+url+trg;
 


meniu.xml
Code:

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

<menu>

<button text="Text1"  url="http://www.domain.com" target="_parent"></button>
<button text="Text2"  url="http://www.domain.com" target="_parent"></button>
<button text="Text3"  url="http://www.domain.com" target="_parent"></button>
<button text="Text4"  url="http://www.domain.com" target="_parent"></button>
<button text="Text5"  url="http://www.domain.com" target="_parent"></button>

</menu>
 


i just can not see why i get a NaN
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 10939713
hi, okay your approach is totally different to what i had in mind. i was thinking along the lines of txt files.

at what point do you get NaN?

i've just copied your code, will give it a bang (xml and i arent' good friends).

0
 
LVL 4

Author Comment

by:pdd
ID: 10941981
if i want to display rand1.text i get the NaN

if you have other ideea how to do this .. will work for me ... so maybe you can provide some help
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 10946617
hi, i think your problem is the xml hasn't had a chance to load yet.

i had a look through what documentation i had and here's what i'd do.

firstly, create a movieclip with 3 frames to simulate the up, over and down states of the buttons (if you want that). Then give it an identifier (in this example, its attached dynamically using attachMovie).

then, in the first keyframe.
menuXml = new XML();
menuXml.ignoreWhite = true;
menuXml.onLoad = function(success) {
      if (success) {
            menuItem = this.firstChild.childNodes;
            for (var i = 0; i<menuItem.length; i++) {
                  item = _root.attachMovie("itemClip", "itemClip"+i, i);
                  item._x = 0;
                  item._y = 20*i;
                  item.itemLabel.text = menuItem[i].attributes.name;
                  item.myUrl = menuItem[i].attributes.url;
                  item.onRollOver = function() {
                        this.gotoAndStop(2); //over state
                  };
                  item.onRollOut = function() {
                        this.gotoAndStop(1);//up state
                  };
                  item.onRelease = function() {
                        this.gotoAndStop(1);
                        getURL(this.myURL, "_blank");
                  };
                  item.onPress = function() {
                        this.gotoAndStop(3);
                  };
            }
      }
};
menuXml.load("myMenu.xml");

hope that makes sense.
in this example, the buttons are laid out to form a vertical menu, you can adjust the item._x and item._y according to your needs.

blu.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:pdd
ID: 11053903
Hi

sorry for replying so late.

I've tried the code but it didn't help

I am a beginner at this can you provide a fla file ?
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 200 total points
ID: 11059731
ok - go have a look here.
http://www.geocities.com/bluegenie_sa/pdd/menu.zip

check and take note of how i've set up my xml file, if yours is structured differently, then you'll need to change your structure in terms of the childnodes and attribute names.

blu.
0
 
LVL 4

Author Comment

by:pdd
ID: 11060485
the URL is wrong

This is the valid URL: http://www.geocities.com/bluegenie_sa/pdd/xmlbuttons.zip

I'll take a look and get back

thanks
0
 
LVL 4

Author Comment

by:pdd
ID: 11061891
hi

it's ok now

but one more thing

not all the texts for links have same length
how can i show them on center? i've changed the button. i need so when the mouse is over the text, the color to change.

you can get what i've changed from here: www.protung.ro/meniu.zip
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 11068364
to center the text simply center align your textfield.
you can change the autosize property of your textfield.
re. the rollover states, you'll notice that my example has them (remember your buttons have to be movieclips in order to acheive that).

blu.
0
 
LVL 4

Author Comment

by:pdd
ID: 11069920
In the end i will use this. it's better for what i want to make in the end

the problem i have is that i can not make the CSS file to work. after i define the style for links in the css file they do not have any impact.
any special setting i have to do ?



var css_styles = new TextField.StyleSheet();
css_styles.load("styles.css");
css_styles.onLoad = function(ok) {
      if (ok) {
            // display style names
            trace(this.getStyleNames());
      } else {
            trace("Error loading CSS file.");
      }
};
menuXml = new XML();
menuXml.ignoreWhite = true;
menuXml.onLoad = function(success) {
      if (success) {
            menuItem = this.firstChild.firstChild.childNodes;
            //for (j=1; j<=4; j++) {
            for (i=0; i<menuItem.length; i++) {
                  rand1.htmlText += "<a href=\""+menuItem[i].attributes.url+"\">"+menuItem[i].attributes.text+"</a>";
            }
            //}
      }
};
menuXml.load("meniu.xml");
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now