Solved

ActionScript syntax: rollOver, rollOut to change text color of dynamic tb in xml-fed menu mc

Posted on 2006-06-08
5
1,947 Views
Last Modified: 2012-05-05
Hi there experts, I have a simple menu that refers to a simple xml file and drops a simple movie clip (containing a pretty rectangle and a dynamic textbox) for each xml element in my file. I would like to simply change the color of text on rollover and then back again when rolling out. Below, I tried the Baroque little comment there, and also one more like my item.onRelease down there. It hasn't been so simple. It isn't a button, and if I change it to a button, it doesn't populate the field. There is nothing on the stage, but only in the library. The instances at runtime are sequentially numbered: "itemClip1, itemClip2, etc." So I think this is something simple that I've missed. Let me know if you have any questions about my explanation, too. I've tried various permutations of differently scoped stuff. Thanks!

PS I put "moderately diificult", though it's not so much--and this is just because I would very much appreciate a brief explanation of the answer so I might learn the why of it...


menuXml = new XML();
menuXml.ignoreWhite = true;
menuXml.onLoad = function() {
      menuItem = this.firstChild.childNodes;
      for (var i = 0; i<menuItem.length; i++) {
            item = _root.attachMovie("itemClip", "itemClip"+i, i);
            item._x = 0;
            item._y = 18*i;
            item.itemLabel.text = menuItem[i].attributes.name;
            item.itemLabel2.text = menuItem[i].attributes.name;
            item.myUrl = menuItem[i].attributes.url;
            item.onRelease = function() {
                  getURL(this.myUrl, "_top");
            };
            //_level0.itemClip.item.onRollOver = function() {
                  //trace("yo, mc rollin' over here."); //oh no it's not :)
            };
      }
};
0
Comment
Question by:Abbadona
  • 3
5 Comments
 
LVL 19

Expert Comment

by:Montoya
ID: 16869913
Hey there. Do you think you could upload the file? It is so much easier that way. (pls include a sample xml as well).

Now, in the meantime, here is my quick thought.

Why not use the for() loop to add the names to an array. Then, use the items inside the array to apply your rollovers. Afterall, your "items" will be something like itemClip[i].onRollOver=function(){ ... and so on. Or, itemClip[i].item.onRollOver. Again, this would be easier if we could just work on the file. (at least for me, as it saves time)

Regards,

Montoya
0
 

Author Comment

by:Abbadona
ID: 16873947
Hi there, I use an ASP page, so I made this version with a plain XML file. The output validates the same though, and doesn't affect the task at hand. So you'll see in there that it's red text on a gray field. I might like to add a small movieclip or something later on, but for now, I am just trying to rollover the text and have the text turn white, then back to red on rollout. I'd like to do it in AS if possible, rather than adding a hidden button or something that might make a fatter file or more difficult maintenance. Thank you for your reply Youaremontoya, here's the file:

http://tinyurl.com/jv95u

I will try some of the stuff you've mentioned in the meantime, and see if I can get anything to stick. (After lunch!)

See you, --A
0
 
LVL 7

Accepted Solution

by:
madgett earned 200 total points
ID: 16875197
You need to set up a TextFormat object on the TextField(s):

menuXml = new XML();
menuXml.ignoreWhite = true;
menuXml.onLoad = function() {
      menuItem = this.firstChild.childNodes;
      for (var i = 0; i<menuItem.length; i++) {
            item = _root.attachMovie("itemClip", "itemClip"+i, i);
            item._x = 0;
            item._y = 18*i;
            item.itemLabel.text = menuItem[i].attributes.name;
            item.itemLabel2.text = menuItem[i].attributes.name;
            item.myUrl = menuItem[i].attributes.url;
            item.onRelease = function() {
                  getURL(this.myUrl, "_top");
            };
            var tf:TextFormat = new TextFormat();
            tf.color = 0xFF0000;
            item.itemLabel.setTextFormat(tf);
            item.onRollOver = function() {
                  var gtf:TextFormat = this.itemLabel.getTextFormat();
                  gtf.color = 0xFFFFFF;
                  this.itemLabel.setTextFormat(gtf);
            }
            item.onRollOut = function() {
                  var gtf:TextFormat = this.itemLabel.getTextFormat();
                  gtf.color = 0xFF0000;
                  this.itemLabel.setTextFormat(gtf);
            }
      }
};
ran = random(1000000);
menuXml.load("navigation.xml");
0
 

Author Comment

by:Abbadona
ID: 16875329
Oh that works well--thank you. I'll read up on that object. That's something wouldn't have guessed. Thanks, IamM.! --A
0
 

Author Comment

by:Abbadona
ID: 16875334
I mean Madgett! Sorry. thank you very much. --A
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
playing flash video on kiosk at startup 6 410
Adobe flash player fails to install 12 311
black magic design 1 130
Can't enable Flash on Chrome 32 Windows 7 any more 2 22
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

792 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