263 posts
  • Antarctica
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 100 and 1 000 dollars
x360c says
How can I get a function to work like this:
function01(mcName,{prop1:'asdf',prop2:'asdf');
Like with tweener, thanks in advance.
2309 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 100 and 1 000 dollars
  • United States
theflyingtinman says
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 :)

282 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
  • United States
Fougie says
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).

282 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
  • United States
Fougie says
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.

2309 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 100 and 1 000 dollars
  • United States
theflyingtinman says
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.

2309 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 100 and 1 000 dollars
  • United States
theflyingtinman says

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.

by
by
by
by
by
by