Solved

dynamic button

Posted on 2004-04-28
12
156 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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 last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
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.

628 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