7 Replies Latest reply on Jan 16, 2009 4:30 PM by clbeech

    Making a movie clip colour change perminant for the runtime

    mike670
      I have managed to use a simple change colour script to get my movie clip to change to the users chosen colour scheme and ive tryed but i cant find any way to make it stay threw out the whole story based on the user chosen colour scheme i was hpoing some one might no some code or tell me where im going wrong the code im using so far is :-

      on (press) {
      set(my_colour2, "/shapein");
      var my_colour2:Color = new Color("/shapein");
      my_colour2.setRGB(0xFF0000);
      }

      That might be wrong code to use but its in my swf and changes the colour it just doesnt stay threw out the story only on the one frame.
        • 1. Re: Making a movie clip colour change perminant for the runtime
          clbeech Level 3
          this is most likely due to the instance of the clip being 're-instantiated' at different times throughout the program or timeline. another way to go about this would be to 'store' a variable with the chosen color on the main timeline set by the button, an then in the MC add a script the 'retrieves' that variable information and sets the color of the clip any time its instantiated. for instance, on the main timeline first frame construct a method and var to store the color value:

          var userColor = 0xFFFFFF; //set to whatever 'default' color

          ...then within the button handler(s) use:

          on(press) { _root.userColor = 0xFF0000; //red }

          ...then within the first frame of the MC use:

          import flash.geom.ColorTransform;
          import flash.geom.Transform;

          var ct = new ColorTransform();
          ct.rgb = _root.userColor;
          var trans = new Transform(this);
          trans.colorTransform = ct;

          ...that should reset the color to the root variable every time the MC is brought to the stage.
          • 2. Re: Making a movie clip colour change perminant for the runtime
            mike670 Level 1
            This seems to be the soloution for my problem how ever when it comes to the on press bit to update the veriable with the new colour it doesnt work the buttons in affect become useless whats the resoloution for this is the script wrong?

            on the main timeline first frame construct a method and var to store the color value:

            var userColor = 0xFFFFFF; //set to whatever 'default' color

            ...then within the button handler(s) use:

            on(press) { _root.userColor = 0xFF0000; //red }

            ...then within the first frame of the MC use:

            import flash.geom.ColorTransform;
            import flash.geom.Transform;

            var ct = new ColorTransform();
            ct.rgb = _root.userColor;
            var trans = new Transform(this);
            trans.colorTransform = ct;
            • 3. Re: Making a movie clip colour change perminant for the runtime
              clbeech Level 3
              lol - well I guess we also need a method to 'make' the change happen when the button is pressed: so depending on the file structure you could do this in the main timeline like:

              import flash.geom.ColorTransform;
              import flash.geom.Transform;
              var userColor = 0xFFFFFF;

              function setNewColor(clip, color) {
              userColor = color;
              var ct = new ColorTransform();
              ct.rgb = userColor;
              var trans = new Transform(clip);
              trans.colorTransform = ct;
              }

              ...then from the button call:
              on(press) { _root.setNewColor(this, 0xFF0000); }

              if the 'clip' you wish to change is 'not' the button - and /or if there are multiple clips to change, you may need something a bit different to target all of the instances as needed, then you can also 'remove' the clip parameter from both the call and the method, instead targeting the MCs needed to change.
              • 4. Re: Making a movie clip colour change perminant for the runtime
                clbeech Level 3
                ps - though you will still want to 'leave' the color changing code on the MC in order to keep the color that has been set, in the event of the clip being re-instantiated.
                • 5. Re: Making a movie clip colour change perminant for the runtime
                  mike670 Level 1
                  thx for the help wid this issue but its still doesnt seem to work and i cant figure out y lol the script youve provided does the job as long as its all on the same like level as soon as i put in a iddfferenet movie or something then this is where it doesnt work any longer because the way im using it is the cutomise bit is at the start and then once the movieclip is customised to users choice then it begins a story and each room is base in a movieclip and then the custom movieclip is with in the room movie clip and i was hoping to make the users customisation permnant threw out the whole swf till they close or restart am i doing something wrong and do you get that and thnx for the help so far
                  • 6. Re: Making a movie clip colour change perminant for the runtime
                    mike670 Level 1
                    doest matter i just needed to change it to a global variable in ur script n it seemed to work so thx for the script
                    • 7. Re: Making a movie clip colour change perminant for the runtime
                      clbeech Level 3
                      np mike - lol yeah it's often very difficult to tell a person just 'how' to do what they need without 'seeing' the whole picture, this makes debugging quite a challenge - glad you got it working though and you're welcome :)