Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-06-08
5
Medium Priority
?
1,955 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

722 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