Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dynamic button

Posted on 2004-04-28
12
Medium Priority
?
161 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
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.

885 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