Solved

dynamic button

Posted on 2004-04-28
12
153 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

825 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