One generic code for multiple MC's

  • stabmonkeh
  • Born
  • Born
  • stabmonkeh
  • Posts: 2

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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. };
  • stabmonkeh
  • Born
  • Born
  • stabmonkeh
  • Posts: 2

Post 3+ Months Ago

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 16 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
 
cron
 

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