263 posts
  • Has been part of the Envato Community for over 6 years
  • Located in Antarctica
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+1 more
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
  • Has been part of the Envato Community for over 7 years
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
+5 more
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
  • Has been part of the Envato Community for over 7 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+3 more
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
  • Has been part of the Envato Community for over 7 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+3 more
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
  • Has been part of the Envato Community for over 7 years
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
+5 more
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
  • Has been part of the Envato Community for over 7 years
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
+5 more
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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by