Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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 set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
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.

708 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

16 Experts available now in Live!

Get 1:1 Help Now