Jump to content
Search Community

How to pass movieclips as objects

Rashid test
Moderator Tag

Recommended Posts

Hi Jack,

 

Been a big time fan of your articles.

 

Here's a query,

 

I'm trying to pass an object as class, but it simply doesn't work,

 

 

Here's what i m doing separately for each of the movieclips objx

 

 

import com.greensock.*;

obj1.onRollOver = obj1RollOver;

obj1.onRollOut = obj1RollOut;

obj2.onRollOver = obj2RollOver;

obj2.onRollOut = obj2RollOut;

obj3.onRollOver = obj3RollOver;

obj3.onRollOut = obj3RollOut;

obj4.onRollOver = obj4RollOver;

obj4.onRollOut = obj4RollOut;

obj5.onRollOver = obj5RollOver;

obj5.onRollOut = obj5RollOut;

function obj1RollOver() {

TweenMax.to(obj1, .6, {blurFilter:{blurX:8, blurY:8}});

}

function obj1RollOut() {

TweenMax.to(obj1, .6, {blurFilter:{blurX:0, blurY:0}});

}

function obj2RollOver() {

TweenMax.to(obj2, .6, {blurFilter:{blurX:8, blurY:8}});

}

function obj2RollOut() {

TweenMax.to(obj2, .6, {blurFilter:{blurX:0, blurY:0}});

}

function obj3RollOver() {

TweenMax.to(obj3, .6, {blurFilter:{blurX:8, blurY:8}});

}

function obj3RollOut() {

TweenMax.to(obj3, .6, {blurFilter:{blurX:0, blurY:0}});

}

function obj4RollOver() {

TweenMax.to(obj4, .6, {blurFilter:{blurX:8, blurY:8}});

}

function obj4RollOut() {

TweenMax.to(obj4, .6, {blurFilter:{blurX:0, blurY:0}});

}

function obj5RollOver() {

TweenMax.to(obj5, .6, {blurFilter:{blurX:8, blurY:8}});

}

function obj5RollOut() {

TweenMax.to(obj5, .6, {blurFilter:{blurX:0, blurY:0}});

}

 

the above works fine.

 

Now i tried to shorten the above code as below

 

 

 

import com.greensock.*;

obj1.onRollOver = objRollOver(obj1);

obj1.onRollOut = objRollOut(obj1);

obj2.onRollOver = objRollOver(obj2);

obj2.onRollOut = objRollOut(obj2);

obj3.onRollOver = objRollOver(obj3);

obj3.onRollOut = objRollOut(obj3);

obj4.onRollOver = objRollOver(obj4);

obj4.onRollOut = objRollOut(obj4);

obj5.onRollOver = objRollOver(obj5);

obj5.onRollOut = objRollOut(obj5);

 

function objRollOver(myobj:MovieClip) {

TweenMax.to(myobj, .6, {blurFilter:{blurX:8, blurY:8}});

}

function objRollOut(myobj:MovieClip) {

TweenMax.to(myobj, .6, {blurFilter:{blurX:0, blurY:0}});

}

 

 

But this thing simply doesnt work,

 

Would be great if you help me out and also explain why does it not work.

 

Thanks and Regards

Rashid

Link to comment
Share on other sites

you can't pass in arguments when assigning functions to events like that.

as soon as this code:

 

obj1.onRollOver = objRollOver(obj1);

 

is encountered it gets executed immediately

 

 

 

try this:

 

obj1.onRollOver = objRollOver
obj1.onRollOut = objRollOut

function objRollOver() {
TweenMax.to(this, .6, {blurFilter:{blurX:8, blurY:8}});
}
function objRollOut() {
TweenMax.to(this, .6, {blurFilter:{blurX:0, blurY:0}});
}

Link to comment
Share on other sites

Fantastic ! :)

that worked awesome... thanks for helping me out. carl !

Saved a lot of redundant code.

 

Please let me know if i can ask you more queries!

 

Heres another for the same above example

 

I have a tweening on the obj1 it moves from one position to other, and blurs when mouse is over it, the blur filter works fine, but when i try the color transform or brightness filter the tween stops forever (after mouseover).

 

I have tried to search for a solution to this, at some forum i read that I would to wrap the tween around another object of the same type.

 

But i dont know what does this wrapping exactly mean (in AS2 context) and what do we need to do to trick this...

 

 

Thanks for your kind help...

Link to comment
Share on other sites

Glad the other problem is solved. I am not understanding the new problem.

Please provide a very simple example that only includes the code and assets necessary to illustrate what is happening.

 

That whole bit about wrapping tweens I believe relates to putting your obj1 movie clip inside another movie clip. let's call it obj1Parent. If necessary you can apply some tweens to obj1 and others to obj1Parent.

 

this is handy when mixing dropShadow effects and color effects. for instance you could colorize obj1 and put a dropShadow on obj1Parent to make sure the dropShadow doesn't get effected by the color tween.

Link to comment
Share on other sites

Hi Carl,

 

Good evening,

 

Thanks for the explanation about wrapping objects, I tried this out but it didnt work,

 

Thanks for the explanation of drop shadow example.

 

 

Regarding my problem, may be my problem is not quite clear enough...

 

I will try to explain again

 

 

i create a new movieclip mc_1 in this clip i include my obj1 which is motion tweened from one x postion suppose 100 to 200... using flash motion tween.

 

Now i try to apply a colortransform (using tweenmax) on the mouseover event of obj1 as below

TweenMax.to(mc, 1, {colorTransform:{tint:0xff0000, tintAmount:0.5, exposure:0.7, brightness:0.2, redMultiplier:2.1, redOffset:50}});

 

now i include this clip in my main timeline.

 

However when i test this movie, as soon as the mouseover event occurs the tween stops.

 

Let me know how I can solve this thing...

 

In very very simple words i want a movie clip which moves as well as changes color (on mouseover)

 

Please help.

 

Thanks and regards

Eagerly awaiting a reply

Link to comment
Share on other sites

yes, you can't mix timeline animation and also use actionscript to change properties of a movie clip.

 

try this simple example:

 

//mc is a movie clip performing a motion tween on timeline
mc.addEventListener(MouseEvent.ROLL_OVER, onOver);
function onOver(e:MouseEvent):void{
trace("over");
mc.alpha = .5
}

 

so if mc is being controlled by a timeline tween, you will need to nest another clip inside of it that can respond to mouse events.

 

in your case, obj1 should have another movie clip inside it.

Link to comment
Share on other sites

sorry about that.

I made a file for you that illustrates the problem and solution in AS2 (flash cs4).

 

there are 2 movie clips animated with classic tweens. The blue tween breaks on rollover, the red tween works fine because it has a nested clip that has the _alpha being changed.

 

blue.onRollOver = function(){
blue._alpha = 50;
trace("oh no the tween broke!");
}

red.onRollOver = function(){
red.red_bg._alpha = 50;
trace("no problems");
}

brokenTweens.zip

Link to comment
Share on other sites

  • 3 months later...

I know, its been long enough to ask, My system had crashed down and loads of problem back here,

 

now i m back on working with the thing i had asked you, the zip file u sent, i tried opening the file, and flash gives an error saying "unexpected file format". I did saw the swf, yes i want to do something like that. I surf through then net for this problem, I think its their problem, so i m downloading and updater that claims to resolve such errors, will get back to you with my findings.

 

Thanks a ton.

Link to comment
Share on other sites

Oh its a trouble, after googling on the "unexpected file format" error, i understand that you had created the movie clip in some newer version of flash, while mine is an older one, (i m using Macromedia flash 8).

 

If its not a trouble :cry:, could you please save that file in an older version and send to me, again.

 

Thanks again.

Link to comment
Share on other sites

Hi Rashid,

 

Welcome back. Unfortunately there is no way for me to save back to Flash 8. I think that is about 5 versions in the past. Usually any particular Flash version can only save back 1 version. I'm running CS6 so the best I can get you now is CS5 :(

 

I would recommend downloading a trial of CS6 if possible.

Link to comment
Share on other sites

Hi carl,

 

I managed to do something with the wrapping thing but I m not sure whether I did it the right way.

 

Attaching it..

 

Though the movie works fine, but if you notice at the last frame, the color tweenmax effects get cancelled and the red box appears in the original color... no aplha change, no blurry effect, can you provide me some hints as to why this happens and how can i stop this from happening...

eagerly awaiting your reply.....!!

trial3.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...