PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to mantain a movieclip's color between frames?
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How to mantain a movieclip's color between frames?

Hybrid View

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2

    How to mantain a movieclip's color between frames?

    My app has 2 frames; in frame 1 there are 5 MC and on a DOUBLE_CLICK event the target's color change and go to the next frame 2. In frame 2 i have a button to return to frame 1.
    How can i maintain the MC color when i return to frame 1?
    Actionscript Code:
    package
    {
        import flash.display.*;
        import flash.events.*;
        import flash.net.*;
        import flash.geom.ColorTransform;

        public class test extends MovieClip
        {
            public function test()
            {
                var myMCTable:Array = [myMC1,myMC2,myMC3,myMC4,myMC5];
                for (var i:uint = 0; i<myMCTable.length; i++)
                {
                    myMCTable[i].doubleClickEnabled = true;
                    myMCTable[i].addEventListener(MouseEvent.DOUBLE_CLICK, changeColor);
                }
            }

            private function changeColor(e:MouseEvent):void
            {
                var newColorTransform:ColorTransform = (e.target).transform.colorTransform;
                newColorTransform.color = Math.random() * 0xFFFFFF;
                (e.target).transform.colorTransform = newColorTransform;
                nextFrame();
                goBack_btn.addEventListener(MouseEvent.CLICK, goBack);
            }

            private function goBack(e:MouseEvent):void
            {
                prevFrame();
            }
        }
    }
    Attached Images Attached Images

  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Anyone?

  3. #3
    Member
    Join Date
    Sep 2010
    Posts
    37
    I'm not the ace of flash, but I can try to help if you still need it.

    I don't quite get what the problem is, though.
    Firstly, why would you need to go to the next frame, just to have a button to go back?
    It would help if you explain your goal.

    Also, is frame2 a new keyframe? Cus if the movieclips you changed color on are not present in frame 2 and your code is run every frame1, you're just creating the objects over and over again every time you go back.

    Let me know if I've misinterpreted anything.

  4. #4
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    hmm... unfortunately movieclip frames are beyond my ability to figure out... Sometimes it seems it can store and keep color information and sometimes not. Frankly I have written off what you are trying to do completely years and years ago... along with scenes for that matter.

    For you, I would design it differently not relying on frames of a movie clip; This over all would be better for you and your project in the long run.

    However if your stuck with using frames, then the best way to go about doing it would be to store the current color of that movieclip in a variable, then when you go back to that frame use that saved color and apply it to that movieclip, Do this for each movieclip that you have on the stage on that frame.

    Since you are using frames, im guessing you are going to have a set number of these movieclips on the stage on a given frame, all already instanced with unique instance names,... so you can just go through each of them and change their colors when they are displayed on that frame.

    For instance: mc1.//do color transforms here, mc2.//do color transforms here... et al.

    This is a static and gross way to do things, but... it will work (remember though adding any new movieclips will be pretty big pain...).

    However if this is not the case, and you may have a random or unknown amount of movieclips, then... well you should really rethink the way you are thinking about this project- drop trying to do it on frames altogether and look into a more OOP approach.

    Hope that helps,
    -GK>^.^<

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center