differences between MCs and Buttons

  • nornholdj
  • Novice
  • Novice
  • User avatar
  • Posts: 18

Post 3+ Months Ago


I have a series of buttons that I have MouseEvent.CLICK events setup for for which I read in text from a xml file and dynamically change the text on the text box to match whats in the xml file. I originally set them up as Movie Clips but I want to do mouse over animations on them and I know I can do that through code but it seems like it would be much easier to make them a button object rather than a movieclip object. As soon as I change them to a button I can no longer set the text in my code.

My layout:

So I basically have a background and a dynamic textbox on a layer above it. Thats the basics. To dynamically create new buttons I have attached an actionscript class to the button object. When I create the Button I pass the text to it in the constructor.

My Entire Class:

In this class the only thing that refers to anything on the button itself is a dynamic textbox with an instance name of detailText. It also takes advantage of another custom class called DetailEvent which is an event handler. If you must see that class I can post it as well but it seems irrelevant to me.
Code: [ Select ]
package com.ad.website
    import com.ad.website.DetailEvent;
    import flash.text.*;
    import flash.display.*;
    import flash.events.*;
    public class Detail extends SimpleButton
        private var dName:String;
        private var header:String;
        private var detailDescription:String;
        public function Detail(DetailName:String, DetailHeader:String, DetailDescription:String):void
            dName = DetailName;
            header = DetailHeader;
            detailDescription = DetailDescription;
            detailText.text = dName; //this line doesn't work
            addEventListener(MouseEvent.CLICK, onDetailClick);
        private function onDetailClick(e:MouseEvent):void
            dispatchEvent(new DetailEvent(detailDescription, header));
        public function printToTrace():void
  2. package com.ad.website
  3. {
  4.     import com.ad.website.DetailEvent;
  5.     import flash.text.*;
  6.     import flash.display.*;
  7.     import flash.events.*;
  9.     public class Detail extends SimpleButton
  10.     {
  11.         private var dName:String;
  12.         private var header:String;
  13.         private var detailDescription:String;
  15.         public function Detail(DetailName:String, DetailHeader:String, DetailDescription:String):void
  16.         {
  17.             dName = DetailName;
  18.             header = DetailHeader;
  19.             detailDescription = DetailDescription;
  21.             detailText.text = dName; //this line doesn't work
  22.             addEventListener(MouseEvent.CLICK, onDetailClick);
  23.         }
  25.         private function onDetailClick(e:MouseEvent):void
  26.         {
  27.             dispatchEvent(new DetailEvent(detailDescription, header));
  28.         }
  30.         public function printToTrace():void
  31.         {
  32.             trace(name);
  33.             trace(header);
  34.             trace(detailDescription);
  35.         }
  36.     }
  37. }

I just don't understand why it works when the object is a movieClip but not as a Button. What is different about the two and what can I do to fix my problem?


  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 859
  • Loc: BKNY

Post 3+ Months Ago

Buttons just aren't as versatile as MovieClips. Among other things, you can't dynamically send values to a textbox within a button. It would be kind of helpful, too... in figuring this out with you, to see where SimpleButton is declared in the first place.

However, trust that if you make SimpleButton a Button, rather than a MovieClip, you're shooting yourself in the foot in terms of sending values to it.

The good news is that anything you can do with a Button, you can also do with a MovieClip. So it would be best to make a rollover state with actionscript on the MC if want that script (above) to work. It's really not that hard. Is the MovieClip in the library or something? What does the initial SimpleButton declaration look like? It may really be as easy as adding a keyframe to the MC in the library and one or two lines to the SimpleButton declaration.

  • nornholdj
  • Novice
  • Novice
  • User avatar
  • Posts: 18

Post 3+ Months Ago

Yeah that does sound like it will be easiest if its not possible to dynamically access things from actionscript. The movie clip is in the library and the code above is linked to it. I think I'm just going to do the rollover animation in actionscript though, rather than jumping frames. I should be able to be more flexible with the animation.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 3 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.