One generic code for multiple MC's

  • stabmonkeh
  • Born
  • Born
  • No Avatar
  • Joined: Sep 30, 2009
  • Posts: 2
  • Status: Offline

Post September 30th, 2009, 1:56 am

Hello,

I have a flash doc with two MC's (red1 and red2) and two frames.

In frame 1, the user can select one of the MC's, and in frame 2, he can move ONLY that MC.

Is there a way to write a general code in frame 2 and not having to write an "IF" depending an extra variable I had to create?
Because in the future I will have lots of MC's.

Here is the little code I have:

Frame 1
Quote:
stop();

extra_var = 0;

red1.onRelease = function() {
extra_var = 1;
(new Color(red1)).setRGB(0xFF6666);
_root.gotoAndStop(2);
};

red2.onRelease = function() {
extra_var = 2;
(new Color(red2)).setRGB(0xFF6666);
_root.gotoAndStop(2);
};


Frame 2
Quote:
stop();

delete red1.onRelease;
delete red2.onRelease;

if (extra_var == 1) {
red1.onPress = function() {
startDrag(red1, true);
};
red1.onRelease = function() {
red1.stopDrag();
(new Color(red1)).setRGB(0xFF0000);
delete red1.onPress;
delete red1.onRelease;
_root.gotoAndStop(1);
};
};

if (extra_var == 2) {
red2.onPress = function() {
startDrag(red2, true);
};
red2.onRelease = function() {
red2.stopDrag();
(new Color(red2)).setRGB(0xFF0000);
delete red2.onPress;
delete red2.onRelease;
_root.gotoAndStop(1);
};
};



I really need to solve this so I can upload the .fla if necesary.
Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 30th, 2009, 1:56 am

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post September 30th, 2009, 3:23 am

eehehehehehee
i`m sure you still have to learn about OOP.
well, you can assign a variable to the released object, so you will have:
frame 1:
Code: [ Select ]
stop();
var selectedClip = null;

red1.onRelease = red2.onRelease = function()
{
    selectedClip = this;
    (new Color(this)).setRGB(0xFF6666);
    _root.gotoAndStop(2);
};
  1. stop();
  2. var selectedClip = null;
  3. red1.onRelease = red2.onRelease = function()
  4. {
  5.     selectedClip = this;
  6.     (new Color(this)).setRGB(0xFF6666);
  7.     _root.gotoAndStop(2);
  8. };


frame 2:
Code: [ Select ]
stop();
delete red1.onRelease;
delete red2.onRelease;

selectedClip.onPress = function()
{
    startDrag(selectedClip, true);
};

selectedClip.onRelease = selectedClip.onReleaseOutside = function()
{
    this.stopDrag();
    (new Color(this)).setRGB(0xFF0000);
    delete this.onPress;
    delete this.onRelease;
    delete this.onReleaseOutside;
    _root.gotoAndStop(1);
};
  1. stop();
  2. delete red1.onRelease;
  3. delete red2.onRelease;
  4. selectedClip.onPress = function()
  5. {
  6.     startDrag(selectedClip, true);
  7. };
  8. selectedClip.onRelease = selectedClip.onReleaseOutside = function()
  9. {
  10.     this.stopDrag();
  11.     (new Color(this)).setRGB(0xFF0000);
  12.     delete this.onPress;
  13.     delete this.onRelease;
  14.     delete this.onReleaseOutside;
  15.     _root.gotoAndStop(1);
  16. };
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • stabmonkeh
  • Born
  • Born
  • No Avatar
  • Joined: Sep 30, 2009
  • Posts: 2
  • Status: Offline

Post September 30th, 2009, 6:04 am

Thank you so much man. You cant imagine how much you helped me.

Yes, OOP is my weakness :/

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 38 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.