Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dynamic button

Posted on 2004-04-28
12
Medium Priority
?
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

705 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