MC mouseover shrink and grow

  • BardicKnowledge
  • Novice
  • Novice
  • BardicKnowledge
  • Posts: 21
  • Loc: Halifax

Post 3+ Months Ago

Hello,
I have problem that I just can't figure out and was for some help or guidance.

So this is what I'm trying to do: I have 2 blocks on stage (will have more later) and when I mouse over one I want it to grow and the other to shrink. But here's my problem; How do I get all the movieclips on stage instance names, pass the one that was rolled over to the function, and make the rollover function in the root instead of being on each button to get the current MC it's over and it's instance name (if possible)?

right now this is what I have:

Code: [ Select ]
on(

grow = 0.09;

function myFucntion(Oro:MovieClip) {    
    
    onEnterFrame = function(){        
        trace(Oro);
         blueblock._width += blueblock._width * grow;
        blueblock._height += blueblock._height * grow;
        
        greenblock._width -= greenblock._width * grow;
        greenblock._height -= greenblock._height * grow;
    }
}

function stopEnterFrame(){
    delete this.onEnterFrame;
}
  1. on(
  2. grow = 0.09;
  3. function myFucntion(Oro:MovieClip) {    
  4.     
  5.     onEnterFrame = function(){        
  6.         trace(Oro);
  7.          blueblock._width += blueblock._width * grow;
  8.         blueblock._height += blueblock._height * grow;
  9.         
  10.         greenblock._width -= greenblock._width * grow;
  11.         greenblock._height -= greenblock._height * grow;
  12.     }
  13. }
  14. function stopEnterFrame(){
  15.     delete this.onEnterFrame;
  16. }


On the MC I have:

Code: [ Select ]
on(rollOver){
    _root.myFucntion(_name);    
}

on(rollOut){
    _root.stopEnterFrame();
}
  1. on(rollOver){
  2.     _root.myFucntion(_name);    
  3. }
  4. on(rollOut){
  5.     _root.stopEnterFrame();
  6. }


Another little problem is that I pass the instance name on rollover to the root function and it works in a trace but when I try to use the passed value to manipulate size it doesn't work.

Any help would be much appreciated.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

You can change the second block of code into things like below and put them in the root


yourMcName.onRollOver=function(){
myFunction(this);
}
yourMcNme.onRollOver=function(){
stopEnterFrame(this);
}
  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

Also your code on the MC should be "this" instead of "_name"
  • BardicKnowledge
  • Novice
  • Novice
  • BardicKnowledge
  • Posts: 21
  • Loc: Halifax

Post 3+ Months Ago

hey zhaojany,
thanks for the replies.

I have tried the snippet of code you posted and it doesn't want to work for me. I don't get any errors though.

Changing the name to 'this' worked great though. I traced it and seen how it works by passing the level with the name. Thanks :)
  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

Have you named your mc and use the name of you mc instead of "yourMcName".
  • BardicKnowledge
  • Novice
  • Novice
  • BardicKnowledge
  • Posts: 21
  • Loc: Halifax

Post 3+ Months Ago

if you mean use the clip name instead of the instance name I have tried that. I have also tried the instance name
  • BardicKnowledge
  • Novice
  • Novice
  • BardicKnowledge
  • Posts: 21
  • Loc: Halifax

Post 3+ Months Ago

If anyone is interested I have got it doing what I wanted it to do. Here is it

Root:
Code: [ Select ]
grow = 0.09; //speed at which the objects grow/shrink
totalgrowth = 1.5; //how big you want them to grow

var titleArray:Array = new Array("_level0.blueblock","_level0.greenblock","_level0.redblock","_level0.yellowball"); //These have to be hardcoded. Are the instance names of the objects to grow/shrink
var otherImages:Array = new Array();

function myFunction(Oro:MovieClip) {        //Is the main function, calling in the other functions
    
    setOtherImages(Oro);                      //function calls
    setSizes();
    activeItem(Oro);    
        
    onEnterFrame = function(){                
    
        if(Oro._width > (block*totalgrowth)){        //this will stop the grow/shrink when the moused over object is 1.5 times it orignal size
            delete this.onEnterFrame;        // will stop loop
        }else{
            Oro._width += Oro._width * grow;             //will make the active object grow
            Oro._height += Oro._height * grow;            
            
            for(i=0;i<otherImages.length;i++){                 //loops through array shrinking the other objects
                eval(otherImages[i])._width -= eval(otherImages[i])._width * grow;
                eval(otherImages[i])._height -= eval(otherImages[i])._height * grow;
            }
        }        
    }
}

function stopEnterFrame(Oro:MovieClip){  //on mouseout will stop the movie and return all objects back to their orignal size
    delete this.onEnterFrame;
    
    for(i=0;i<titleArray.length;i++){
        eval(titleArray[i])._width = origSize[i][1];
        eval(titleArray[i])._height = origSize[i][2];
    }
}

function setOtherImages(Oro:MovieClip){        //is an array that contains all the objects but the active ones instance names
    var counter = 0;
    for (var i = 0; i<titleArray.length; i++){
        if(eval(titleArray[i])!= Oro){            
            otherImages[counter] = titleArray[i];
            counter += 1;            
        }
    }
}

function setSizes(){        //this multidimensional array stores all the objects orignal size
    origSize = new Array();         //outside array
    for (var i = 0; i<titleArray.length; i++){
        origSize[i] = new Array();        //inner array. need to be definded with the [i]
        for (var ii=0; ii<2;ii++){        // loops twice
            if(ii = 1){                 // if loop equals one, store the width
                origSize[i][ii] = eval(titleArray[i])._width;                
            }
            if(ii = 2){                    // if loop equals two, store the height
                origSize[i][ii] = eval(titleArray[i])._height;
            }
        }
    }
}

function activeItem(Oro:MovieClip){                         //this function finds the active movieclip by comparing the passed value (from the button) to the titleArray array.
    for(var i=0;i<titleArray.length;i++){                    // It then uses the titleArrays row to find the width of the active object in the origSize array. This is to set growth limits.
        if(Oro == eval(titleArray[i])){            
            block = origSize[i][1];    
        }
    }
}
  1. grow = 0.09; //speed at which the objects grow/shrink
  2. totalgrowth = 1.5; //how big you want them to grow
  3. var titleArray:Array = new Array("_level0.blueblock","_level0.greenblock","_level0.redblock","_level0.yellowball"); //These have to be hardcoded. Are the instance names of the objects to grow/shrink
  4. var otherImages:Array = new Array();
  5. function myFunction(Oro:MovieClip) {        //Is the main function, calling in the other functions
  6.     
  7.     setOtherImages(Oro);                      //function calls
  8.     setSizes();
  9.     activeItem(Oro);    
  10.         
  11.     onEnterFrame = function(){                
  12.     
  13.         if(Oro._width > (block*totalgrowth)){        //this will stop the grow/shrink when the moused over object is 1.5 times it orignal size
  14.             delete this.onEnterFrame;        // will stop loop
  15.         }else{
  16.             Oro._width += Oro._width * grow;             //will make the active object grow
  17.             Oro._height += Oro._height * grow;            
  18.             
  19.             for(i=0;i<otherImages.length;i++){                 //loops through array shrinking the other objects
  20.                 eval(otherImages[i])._width -= eval(otherImages[i])._width * grow;
  21.                 eval(otherImages[i])._height -= eval(otherImages[i])._height * grow;
  22.             }
  23.         }        
  24.     }
  25. }
  26. function stopEnterFrame(Oro:MovieClip){  //on mouseout will stop the movie and return all objects back to their orignal size
  27.     delete this.onEnterFrame;
  28.     
  29.     for(i=0;i<titleArray.length;i++){
  30.         eval(titleArray[i])._width = origSize[i][1];
  31.         eval(titleArray[i])._height = origSize[i][2];
  32.     }
  33. }
  34. function setOtherImages(Oro:MovieClip){        //is an array that contains all the objects but the active ones instance names
  35.     var counter = 0;
  36.     for (var i = 0; i<titleArray.length; i++){
  37.         if(eval(titleArray[i])!= Oro){            
  38.             otherImages[counter] = titleArray[i];
  39.             counter += 1;            
  40.         }
  41.     }
  42. }
  43. function setSizes(){        //this multidimensional array stores all the objects orignal size
  44.     origSize = new Array();         //outside array
  45.     for (var i = 0; i<titleArray.length; i++){
  46.         origSize[i] = new Array();        //inner array. need to be definded with the [i]
  47.         for (var ii=0; ii<2;ii++){        // loops twice
  48.             if(ii = 1){                 // if loop equals one, store the width
  49.                 origSize[i][ii] = eval(titleArray[i])._width;                
  50.             }
  51.             if(ii = 2){                    // if loop equals two, store the height
  52.                 origSize[i][ii] = eval(titleArray[i])._height;
  53.             }
  54.         }
  55.     }
  56. }
  57. function activeItem(Oro:MovieClip){                         //this function finds the active movieclip by comparing the passed value (from the button) to the titleArray array.
  58.     for(var i=0;i<titleArray.length;i++){                    // It then uses the titleArrays row to find the width of the active object in the origSize array. This is to set growth limits.
  59.         if(Oro == eval(titleArray[i])){            
  60.             block = origSize[i][1];    
  61.         }
  62.     }
  63. }


Buttons
Code: [ Select ]
on(rollOver){
    _root.myFunction(this);    
}

on(rollOut){
    _root.stopEnterFrame(this);
}
  1. on(rollOver){
  2.     _root.myFunction(this);    
  3. }
  4. on(rollOut){
  5.     _root.stopEnterFrame(this);
  6. }

Post Information

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

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