Search  

ADDTWEEN LIKE PROPERTIES IN FUNCTION.

HomeForumsHelp NeededaddTween like properties in function.
24717 x360c
222 posts
Sold between 100 and 1 000 dollars Bought between 1 and 9 items
How can I get a function to work like this:
function01(mcName,{prop1:'asdf',prop2:'asdf');
Like with tweener, thanks in advance. Posted 2 months ago
60461 theflyingtinman
476 posts
Item was featured Sold between 1 and 100 dollars
How can I get a function to work like this:
function01(mcName,{prop1:'asdf',prop2:'asdf'});
Like with tweener, thanks in advance.

Declare you function like this: (then call it as you have above)

function function01(mc:MovieClip, properties: Object) 
{
    trace  (mc);  // result = "[object MovieClip]" 
    trace (properties.prop1);  // result "asdf" 
    trace (properties.prop2);  // result "asdf" 
}

BTW – I don’t accept thanks in advance .. I want more thanks now :)

Posted 2 months ago
16450 Fougie
282 posts
Exclusive author Author was featured Referred at least one person Sold between 5 000 and 10 000 dollars Bought between 1 and 9 items
Well that’s a fair bit of work, but the basic idea would be lines of code like this:
function changeMyMC(movieClip, newWidth, newAlpha) {
eval(movieClip)._width = newWidth;
eval(movieClip)._alpha = newAlpha;
}
Of course, if you wanted a tween, the function would have to occur gradually over time. One easy way to accomplish this, would be to use an onEnterFrame, like so:
function tweenMyAlpha(movieClip, incrementAlpha, numFrames) {
eval(movieClip).framesLeft = numFrames;
eval(movieClip).onEnterFrame = function() {
if(this.framesLeft > 0) {
this._alpha += incrementAlpha;
}else{
this.onEnterFrame = null;
}
}

If you use an onEnterFrame, just remember that the function won’t trigger during the same frame that you made the function (only the frames after it).

Posted 2 months ago
16450 Fougie
282 posts
Exclusive author Author was featured Referred at least one person Sold between 5 000 and 10 000 dollars Bought between 1 and 9 items
How can I get a function to work like this:
function01(mcName,{prop1:'asdf',prop2:'asdf'});
Like with tweener, thanks in advance.

Declare you function like this: (then call it as you have above)

function function01(mc:MovieClip, properties: Object) 
{
    trace  (mc);  // result = "[object MovieClip]" 
    trace (properties.prop1);  // result "asdf" 
    trace (properties.prop2);  // result "asdf" 
}

BTW – I don’t accept thanks in advance .. I want more thanks now :)

Oh, you just want to use an object in the parameters? Yeah what he said then.

Posted 2 months ago
60461 theflyingtinman
476 posts
Item was featured Sold between 1 and 100 dollars
Well that’s a fair bit of work, but the basic idea would be lines of code like this:

I could be wrong but I think x360 is asking how to use an object to pass a variable and unordered set of parameters to a function (like Tweener) not to reproduce the functionality of Tweener.

Posted 2 months ago
60461 theflyingtinman
476 posts
Item was featured Sold between 1 and 100 dollars

BTW when I have a lot of properties I want to pass to such a function, for readability, instead of creating the object anonymously in the function call (using curly braces) I will instantiate and initialize an object outside the parameter list, then jsut pass a reference to it in the function call. In your example case that would look like:

var params: Object = new Object();
params.prop1 = "asdf";
params.prop2 = "asdf";
...
etc.

then call the function like this :

function01( mcName, params);

The function body does not need to change to handle this.

You can, of course, use this method with Tweener, etc.

Posted 2 months ago