1 Reply Latest reply on Aug 2, 2006 12:25 AM by Newsgroup_User

    Creating a Button Class from MC

    vin-E
      I have a few simple questions for those who know about classes. I have been reading the tutorials on creating classes and specifically extending the MC class. I am pretty sure that an extended MC_Class might help me get what I need from my project.

      I essentially have a bunch of buttons, hundreds to be exact - and the exact number needs to be dynamic. Each one is currently a static MC with a bunch of variables assigned to each one via global variables. Its iis pulling in data taht assign the button values from XML files and - these XML files may change.

      Q1. If I extend the MC class so I can add attributes to MC's instance (Avoiding global variables) - will it mess with the rest of the movie clips in my scene? I mean if all I want to do is ad a a few dynamic string variables - it really shouldnt effect any of the other clips would it? MC.JumpURL = "newurl.com", MC.Thumnail ="/here/image.jpg" (This would help alot)

      Q2. What if I wanted to define actions of the new MC in the class? If the MC is an extension of the MC class. Would all of my MC's automatically take on the actions of the custom MC Class? For instance - I want the movieclip to animate onscreen and have rollover effects. I could do this easy if it were static - but I need this to become dynamic. Also - there are now unknown quantities to deal with

      Q3. How exactly would I call and assign the MC its atributes at the same time? And how do I specify this MC to use the functions defined in the class and not the other MC's I created elsewhere in the File.

      Example. Currently I have a grid of MCs' created when the User clicks a menu item (Another type of MC).
      Each new MC animates onstage - it calls a loadMovie(_root.thumb[0], this.Flipper) to assign and embedded MC an image defined in the XML that was loaded and assigned because I placed the instance on stage and wrote a MC script on each MC.

      Confused - check out what I am creating at www.vincesidwell.com/Fischer

      Click Fabrication or TurboSystems menus. Both menues will load a new set of Thumbnails at the bottom. They are loaded via an XML loaded by the menu and a function assigns the jpgs for the main gallery, Rollover image, and eventually a URL for a downloadable High Res Image.

      The client recently added more than 9 images per menu item. I will need to create a scrollable thumbnail gallery with dynamic quantities

      I can manually create the MC Scroller item for static number of buttons. But scripting an unknown for each ones links and images is insane. So I am looking at Classes. Assign a custom class for the flipping buttons and I should be able to assign tthem as the XML loads, and have it automatic. (pray please please please)

      Anyhelp?

      Thanks
      Vince Sidwell

        • 1. Re: Creating a Button Class from MC
          Level 7
          Hi there!

          I'll try and give some answers to your questions below...

          "vin-E" <webforumsuser@macromedia.com> wrote in message
          news:eapbs7$nvr$1@forums.macromedia.com...
          >I have a few simple questions for those who know about classes. I have
          >been
          > reading the tutorials on creating classes and specifically extending the
          > MC
          > class. I am pretty sure that an extended MC_Class might help me get what
          > I
          > need from my project.
          >
          > I essentially have a bunch of buttons, hundreds to be exact - and the
          > exact
          > number needs to be dynamic. Each one is currently a static MC with a
          > bunch of
          > variables assigned to each one via global variables. Its iis pulling
          > in
          > data taht assign the button values from XML files and - these XML files
          > may
          > change.
          >
          > Q1. If I extend the MC class so I can add attributes to MC's instance
          > (Avoiding global variables) - will it mess with the rest of the movie
          > clips in
          > my scene? I mean if all I want to do is ad a a few dynamic string
          > variables -
          > it really shouldnt effect any of the other clips would it? MC.JumpURL =
          > "newurl.com", MC.Thumnail ="/here/image.jpg" (This would help alot)

          You do not have to create a new MC class to assign local values or functions
          to it. A pseudo code example:
          Loop through total buttons you want to make (which can be number of entries
          in an XML file)
          Create a new movieclip and load the button graphic into this, give it a
          name like
          MyButtonX, where X is an increasing number based on which button this
          is. (Instead of creating
          and empty movielcip, you could also attach a movie (or button) from
          library.
          Assign the values and create the functions for this button that you
          would like (probably based
          on information in the XML file):
          MyButtonX.someVariable = node.attribues.someData;
          createOnRelease(MyButtonX, someOtherParamters)
          (where you have defined the function createOnRelease to do something
          like
          function createOnRelease(MC, someOtherParameteres) {
          MC.onRelease = function() {
          do what you want to do based on someOtherParameteres
          }
          }
          Position and resize MyButtonX
          In your example you have a 3x3 grid, which might extend to 3xTOTAL,
          so you'd have to use some
          mathematical formula based on the value X, something like
          MyButtonX._x = (((X-1)%3)*(buttonWidths+hSpaceBetweenButtons)
          MyButtonY._y = Math.floor((X-1)/3)*(buttonHeights
          +vSpaceBetweenButtons
          end of loop.


          >
          > Q2. What if I wanted to define actions of the new MC in the class? If
          > the MC
          > is an extension of the MC class. Would all of my MC's automatically take
          > on
          > the actions of the custom MC Class? For instance - I want the movieclip
          > to
          > animate onscreen and have rollover effects. I could do this easy if it
          > were
          > static - but I need this to become dynamic. Also - there are now unknown
          > quantities to deal with

          If you actually create a new class, than all instances of that class will
          have the methods you define for it (just like all instances of a movieclip
          has those methods. At least, have them available. That doesn't mean they are
          always in use ... like for example the onRollOver. But again, you don't need
          to create a class to give all your dynamically created buttons a rollover
          effect. (Check code above).

          > Q3. How exactly would I call and assign the MC its atributes at the same
          > time? And how do I specify this MC to use the functions defined in the
          > class
          > and not the other MC's I created elsewhere in the File.

          You use the instance name of the MC to access that MC and its
          attributes/methods. For example button number 10 might look like this:
          trace(MyButton10._x);
          trace(MyButton10.someVariableYouHaveDefined);
          MyButton10.callSomeFunctionYouHaveDefined();
          For a movieclip to access a variable that has been defined for that instance
          of the movieclip, use "this" to point to that particular instance. So if we
          defined the function "callSomeFunctionYouHaveDefined" for button number 10
          and want to access "someVariableYouHaveDefined" for this particular
          instance, then
          MyButton10.callSomeFunctionYouHaveDefined = function() {
          trace(this.someVariableYouHaveDefined);
          }

          > Example. Currently I have a grid of MCs' created when the User clicks a
          > menu
          > item (Another type of MC).
          > Each new MC animates onstage - it calls a loadMovie(_root.thumb[0],
          > this.Flipper) to assign and embedded MC an image defined in the XML that
          > was
          > loaded and assigned because I placed the instance on stage and wrote a MC
          > script on each MC.
          >
          > Confused - check out what I am creating at www.vincesidwell.com/Fischer
          >
          > Click Fabrication or TurboSystems menus. Both menues will load a new set
          > of
          > Thumbnails at the bottom. They are loaded via an XML loaded by the menu
          > and a
          > function assigns the jpgs for the main gallery, Rollover image, and
          > eventually
          > a URL for a downloadable High Res Image.
          >
          > The client recently added more than 9 images per menu item. I will need
          > to
          > create a scrollable thumbnail gallery with dynamic quantities
          >
          > I can manually create the MC Scroller item for static number of buttons.
          > But
          > scripting an unknown for each ones links and images is insane. So I am
          > looking
          > at Classes. Assign a custom class for the flipping buttons and I should
          > be
          > able to assign tthem as the XML loads, and have it automatic. (pray please
          > please please)

          Again, no need for a class for this. If you load the buttons into seperate
          MCs, and make sure to have all these MCs created inside a common parent MC
          for these buttons (which then _only_ contains these buttons). You can move
          this parent MC up and down on the stage based on the scrollbar. And you can
          read height off this MC to create your scrollbar.

          You might want to check out the following tutorials at
          http://www.gotoandlearn.com/:
          XML Video Playlist
          Creating Animated Buttons
          Introduction to OOP

          Now, I've said many times you don't need to make your own class to do what
          you want. That does not mean you can't make your own class. I just think
          that the main problem you are facing is the dynamic part, which you will be
          facing if you make your own class or not.

          /Jensen/

          >
          > Anyhelp?
          >
          > Thanks
          > Vince Sidwell
          >
          >
          >