onclipevent alpha problems using multiple movies

  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

--------------------------------------------------------------------------------

can someone help me here...

presently trying to alpha two movie clips located on different layers but the same frame - by using the the onclipevent for the first movie. e.g.

portion of code below:

onClipEvent (enterFrame) { // runs a hit test
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.nextFrame(); // if true the mc plays forward
_root.instearneck4._alpha = 50;
_root.instearneck5._alpha = 50;
} else {
this.prevFrame(); // if not plays backwards to beginning
_root.instearneck4._alpha = 100;
_root.instearneck5._alpha = 100;
}
}


Note: if i remove one of the movies it tends to work fine presently 3 movies on the screen and what should happen is if i put mouse over one of the movies the other two should alpha to 50 and do the opposite when i remove the mouse form over the movie clip.. been bugging me for couple of days now.. need some help

Thanks
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

do the movie clips exist on the following frames of the clip? Make sure the clips are on one layer that goes for the length of the clip. I'm assuming the problem occurs because the clips (instearneck4/5) cease to exist before the script runs
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

well the movies exist on different frames... i have been playing around with _parent and _root to reference these movies

on layer 1 is inst*3
on layer 2 is inst*4
on layer 3 is inst*5

they are all contained on the same frame which is 3.
all in all there is 30 to 40 movies that i need to do the same effect. 30 - 40 different pages of items need viewing and fading out. This is the first issue i have come across and it affects every page with 3 items on it.

note: i am using buttons to move from one frame to the other to view multiple layers with movies that i want this effect applied to. Then with the mouse over the specified movie the other 2 should alpha.

do you request the .fla file?

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

Post 3+ Months Ago

this is the reason why i don't modify already existing templates :D
they are indeed nice as graphics and effects, but suck @ the programming mode.
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

ok ya got me...

time was an issue and still is - gonna get my ass kicked if is not done by monday so urgent help is required to get the at least the idea of this complicated issue so not to make the same mistake again

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

Post 3+ Months Ago

your problem has a very simple solve, and you are very close to it.
This is what i suggest you.
Create a new flash document,
create a mc with 2 layers, layer 1 - the graphic, layer 2 - actionscript,
place a shape in layer 1 and tween it for let's say 10 frames -> simple _y or _x tween, to see it animates somehow. Then place in layer 2 in first frame and last frame: stop();
Next place 3 instances of your movieclip on the stage in first frame of the timeline, and name their instances : instearneck3, instearneck4, instearneck5,
then add the code you already posted on the movieclip called instearneck3 and test the movie. It works, isn't it?
Add the same code on the other 2 movieclips, but for instearneck4, change in the actionscript instearneck4 with instearneck3 and for instearneck5 change in actionscript instearneck5 with instearneck3.
All of them should behave the same. Right? Wroooonnnggg, very wrong.
And you know why? Because in one movieclip on hittest you set the alpha of the others two to 50, on the others two if is not rollovered, they are set back to 100 .... so here you go: 50 .... 100, 50 ... 100 -> of course is not behaving correctly.
I know, i know, you were so close ... and yet so far.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

now, here is what you can do:
place in the timeline, in a keyframe somewhere before the movieclips:
_root.isMCActive = true;
next change your action for your movieclips like this (remember to do the changes in the actionscript of each movieclip):
Code: [ Select ]
onClipEvent (enterFrame)
{ // runs a hit test
    if (this.hitTest(_root._xmouse, _root._ymouse, true))
    {
        _root.isMCActive = true;
        this.isMCActive = true;
        _root.instearneck4._alpha = 50;
        _root.instearneck5._alpha = 50;
        this.nextFrame(); // if true the mc plays forward
    }
    else
    {
        if (!_root.isMCActive || this.isMCActive)
        {
            _root.isMCActive = false;
            this.isMCActive = false;
            _root.instearneck4._alpha = 100;
            _root.instearneck5._alpha = 100;
            this.prevFrame(); // if not plays backwards to beginning
        }
    }
}
  1. onClipEvent (enterFrame)
  2. { // runs a hit test
  3.     if (this.hitTest(_root._xmouse, _root._ymouse, true))
  4.     {
  5.         _root.isMCActive = true;
  6.         this.isMCActive = true;
  7.         _root.instearneck4._alpha = 50;
  8.         _root.instearneck5._alpha = 50;
  9.         this.nextFrame(); // if true the mc plays forward
  10.     }
  11.     else
  12.     {
  13.         if (!_root.isMCActive || this.isMCActive)
  14.         {
  15.             _root.isMCActive = false;
  16.             this.isMCActive = false;
  17.             _root.instearneck4._alpha = 100;
  18.             _root.instearneck5._alpha = 100;
  19.             this.prevFrame(); // if not plays backwards to beginning
  20.         }
  21.     }
  22. }

If you want the movieclip to completly go back and only it's alpha to change (now if you fast switch from a mc to another it will freeze the animation too), then make this simple change:
Code: [ Select ]
    else
    {
        this.prevFrame(); // if not plays backwards to beginning
        if (!_root.isMCActive || this.isMCActive)
        {
            _root.isMCActive = false;
            this.isMCActive = false;
            _root.instearneck4._alpha = 100;
            _root.instearneck5._alpha = 100;
        }
    }
  1.     else
  2.     {
  3.         this.prevFrame(); // if not plays backwards to beginning
  4.         if (!_root.isMCActive || this.isMCActive)
  5.         {
  6.             _root.isMCActive = false;
  7.             this.isMCActive = false;
  8.             _root.instearneck4._alpha = 100;
  9.             _root.instearneck5._alpha = 100;
  10.         }
  11.     }
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

well IceCold....

got a hand to ya... you are actually Ice Cool too. I actually started to flap and lost it. Seems so easy now you have gave me a run down.

My lack of understanding of the onclipevent(enterframe) was what mainly threw me. An assumption that the alpa would not be taken into consideration on the other movies unless the mouse was over them. All in all a lesson learnt to keep my cool under pressure and if all else fails... you know i will be back.

Thanks again... you have saved my bacon.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

I rarely use action on a button or movieclip, prefer to do it in a keyframe.
I will show you another approach of your problem. This method has the advantage that you can manipulate as many movieclips which you want to behave the same, also only one onEnterFrame is used. It is a bit more of code (not too much though), but it will spare you from the copy/paste and replace for each movie clip.
So, this is what you have to do: remove the code from all 3 movieclips, then, in the timeline, in a keyframe where the movieclips exists:
Code: [ Select ]
function SetObjAlpha(nObjID, nValue)
{
    var nIndex:Number;
    for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
    {
        if (nIndex != nObjID)
            this["instearneck"+nIndex]._alpha = nValue;
    }
}

function SetObjID()
{
    var nIndex:Number;
    for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
    {
        this["instearneck"+nIndex].nID = nIndex;
    }    
}

function GetSelectedObj()
{
    var nIndex:Number;
    var crtMC:MovieClip;
    var isObjSelected:Boolean = false;
    for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
    {
        crtMC = this["instearneck"+nIndex];
        if (crtMC.hitTest(this._xmouse, this._ymouse, true))
        {
            selectedObj = crtMC;
            isObjSelected = true;
            selectedObj.nextFrame();
            SetObjAlpha(selectedObj.nID, 50); // set all other but this alpha to 50
            AnimateBack(selectedObj.nID); // remove this if you want to freeze animation
            break;
        }
    }
    if (!isObjSelected)
    {
        SetObjAlpha(-1, 100); // reset all objects alpha, since there's no obj with index -1
        AnimateBack(-1); // animate back all objects if none is overed
    }
}

function AnimateBack(nObjID)
{
    var nIndex:Number;
    var crtMC:MovieClip;
    for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
    {
        crtMC = this["instearneck"+nIndex];
        if (nObjID != crtMC.nID)
            if (crtMC._currentframe != 1)
                crtMC.prevFrame();
    }        
}

this.onEnterFrame = function()
{
    GetSelectedObj();
}

var nStartIndex:Number = 3;
var nEndIndex:Number = 6;
SetObjID();
stop(); // remove this if you stop the timeline somewhere else
  1. function SetObjAlpha(nObjID, nValue)
  2. {
  3.     var nIndex:Number;
  4.     for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
  5.     {
  6.         if (nIndex != nObjID)
  7.             this["instearneck"+nIndex]._alpha = nValue;
  8.     }
  9. }
  10. function SetObjID()
  11. {
  12.     var nIndex:Number;
  13.     for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
  14.     {
  15.         this["instearneck"+nIndex].nID = nIndex;
  16.     }    
  17. }
  18. function GetSelectedObj()
  19. {
  20.     var nIndex:Number;
  21.     var crtMC:MovieClip;
  22.     var isObjSelected:Boolean = false;
  23.     for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
  24.     {
  25.         crtMC = this["instearneck"+nIndex];
  26.         if (crtMC.hitTest(this._xmouse, this._ymouse, true))
  27.         {
  28.             selectedObj = crtMC;
  29.             isObjSelected = true;
  30.             selectedObj.nextFrame();
  31.             SetObjAlpha(selectedObj.nID, 50); // set all other but this alpha to 50
  32.             AnimateBack(selectedObj.nID); // remove this if you want to freeze animation
  33.             break;
  34.         }
  35.     }
  36.     if (!isObjSelected)
  37.     {
  38.         SetObjAlpha(-1, 100); // reset all objects alpha, since there's no obj with index -1
  39.         AnimateBack(-1); // animate back all objects if none is overed
  40.     }
  41. }
  42. function AnimateBack(nObjID)
  43. {
  44.     var nIndex:Number;
  45.     var crtMC:MovieClip;
  46.     for (nIndex = nStartIndex; nIndex < nEndIndex; nIndex++)
  47.     {
  48.         crtMC = this["instearneck"+nIndex];
  49.         if (nObjID != crtMC.nID)
  50.             if (crtMC._currentframe != 1)
  51.                 crtMC.prevFrame();
  52.     }        
  53. }
  54. this.onEnterFrame = function()
  55. {
  56.     GetSelectedObj();
  57. }
  58. var nStartIndex:Number = 3;
  59. var nEndIndex:Number = 6;
  60. SetObjID();
  61. stop(); // remove this if you stop the timeline somewhere else
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

About being cool under pressure ... is just a matter of thinking. The problem is like this: if you don't finish in the given deadline, then you failed, if you do, all is bright, everyone is happy. But in life we all have ups and downs, so you don't need to worry too much about a failure. One who doesn't know how to lose is a lost man. What you need to do is to traceback your steps and see why you failed and what can you do so next time you won't do the same mistake. There are some reasons why one fail on a given project:
lack of knowledge;
wasting time instead of focusing on the project (this one is my favorite :D); wrong appreciation of the deadline - one can think he can do it, but when starts to work, realize that there are more things to take in consideration than he thought about ... and this usually happen from a superficial view on the project;
sometimes (read:most of times) is the client who usually doesn't have a clear view of what he wants, and you have to present him a prototype first and then he can say what modifications he wants. And most of times he says he wants this, but as the project develops, he will want that, and that, and that, and that .... :D
Just read my signature ... it's a Mark Twain's quote ... and he's so right about it.
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

soo soo true... you'd think i would learn by now ;0)

IceCold,

i did try your above example but came a cropper when nothing happened. I threw some traces to see where it was getting stuck and it seems not to be entering the for loop (within GetSelectedObj() function) no matter what conditions i enter... can you throw us a line

Cheers

Errol187
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

also thought i was home dry with the previous script... now i find that if i load it into a movie container it does strange things... will look in morning again as is getting late...
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

it's all path relative if it doesnt work in a movieclip
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

the movie container that loads the movies is called 'content'... I did add this to the paths i.e _root.content.isMCActive = true;
am assuming that i do not need to add '.content' to the 'this' syntax of the code as it represents the present selection?
  • errol187
  • Novice
  • Novice
  • errol187
  • Posts: 17

Post 3+ Months Ago

ok... found it does not like it when i have two images and fine with 3 - seems like it is me and my coding techniques... Again ;0)

Post Information

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