Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
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 how to record live broadcast.

813 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

17 Experts available now in Live!

Get 1:1 Help Now