Solved

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

Posted on 2006-06-08
5
1,939 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SWF won't scale? 4 520
Firefox video player - embedded native versus VLC player 3 1,063
Does Flash have a Firefox problem? 5 312
Actionscript in Flash 3 46
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…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now