Re: [Flashcoders] Passing a Function as Parameter and call function later

2007-02-18 Thread dr.ache

Hi.

i guess you have a scope problem. for me, your code worked
fine, here my adjustments to test it (i got one MC with a 180 frame
MotionTween starting at 120 when loaded, on the stage, called fred.
i simulated the function call with an interval, so the animation starts and
after 2 seconds, your function rew is called with the parameters
_root.fred and the function which should be called after rewind the 
animation sayHello.


It works. When you use Flash 8, try to understand the Delegate Class,
which should help you handle the scope problem.

hope that helps...
dr.ache

var i:Number = setInterval(this,rew,2000,_root.fred,sayHello);

function rew(m:MovieClip, f:Function) {
   clearInterval(_root.i);
  m.onEnterFrame = function() {
  var cf:Number = m._currentframe;
  var tf:Number = m._totalframes;
  if (cf=tf  cf1) {
  m.gotoAndStop(--cf);
  } else if (cf==1) {
  m.stop();
  if(f) f();
  delete m.onEnterFrame;
  }
  };
}

function sayHello() {
   trace(hallo);
}

Felipe Hefler schrieb:

Hi everyone! I'm having trouble with this issue:
function rew(m:MovieClip, f:Function) {
   m.onEnterFrame = function() {
   var cf:Number = m._currentframe;
   var tf:Number = m._totalframes;
   if (cf=tf  cf1) {
   m.gotoAndStop(--cf);
   } else if (cf==1) {
   m.stop();
   if(f) f();
   delete m.onEnterFrame;
   }
   };
}

When I call this function in an action frame it's like this:
rew(targetpath_movieClipName, _root.play);

What I want is that the function I've passed as a parameter works like a
function later in the code. Messy explanation?? OK OK...
Let's see if I can explain better. If I do something like this:

function rew(m:MovieClip, f:String {
   m.onEnterFrame = function() {
   var cf:Number = m._currentframe;
   var tf:Number = m._totalframes;
   if (cf=tf  cf1) {
   m.gotoAndStop(--cf);
   } else if (cf==1) {
   m.stop();
   if(f == play) play();
   delete m.onEnterFrame;
   }
   };
}

it works perfectly, but I want to call any function and don't wanna 
have to

make a switch for every kind o function.
Has anyone got it?



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Passing a Function as Parameter and call function later

2007-02-18 Thread Felipe Hefler

Thank you dr.ache.

Wasn't that  the problem. Anyway your answer helped me a lot. See what
solution I came up:

function rew(m:MovieClip, f:Function) {
   m.onEnterFrame = function() {
   var cf:Number = m._currentframe;
   var tf:Number = m._totalframes;
   if (cf=tf  cf1) {
   m.gotoAndStop(--cf);
   } else if (cf==1) {
   m.stop();
   if(f) eval(f)();
   delete m.onEnterFrame;
   }
   };
}

But the change was on the way I call the function:
_root.rew(d.mask,_root.nextFrame);

So now if I pass it between  it seems to work fine. But still, there's a
small problem that bothers me. Now I have to use eval(), wich I don't like
at all. Any Ideas on how changing eval to a better solution?



On 18/02/07, dr.ache [EMAIL PROTECTED] wrote:


Hi.

i guess you have a scope problem. for me, your code worked
fine, here my adjustments to test it (i got one MC with a 180 frame
MotionTween starting at 120 when loaded, on the stage, called fred.
i simulated the function call with an interval, so the animation starts
and
after 2 seconds, your function rew is called with the parameters
_root.fred and the function which should be called after rewind the
animation sayHello.

It works. When you use Flash 8, try to understand the Delegate Class,
which should help you handle the scope problem.

hope that helps...
dr.ache

var i:Number = setInterval(this,rew,2000,_root.fred,sayHello);

function rew(m:MovieClip, f:Function) {
clearInterval(_root.i);
   m.onEnterFrame = function() {
   var cf:Number = m._currentframe;
   var tf:Number = m._totalframes;
   if (cf=tf  cf1) {
   m.gotoAndStop(--cf);
   } else if (cf==1) {
   m.stop();
   if(f) f();
   delete m.onEnterFrame;
   }
   };
}

function sayHello() {
trace(hallo);
}

Felipe Hefler schrieb:
 Hi everyone! I'm having trouble with this issue:
 function rew(m:MovieClip, f:Function) {
m.onEnterFrame = function() {
var cf:Number = m._currentframe;
var tf:Number = m._totalframes;
if (cf=tf  cf1) {
m.gotoAndStop(--cf);
} else if (cf==1) {
m.stop();
if(f) f();
delete m.onEnterFrame;
}
};
 }

 When I call this function in an action frame it's like this:
 rew(targetpath_movieClipName, _root.play);

 What I want is that the function I've passed as a parameter works like a
 function later in the code. Messy explanation?? OK OK...
 Let's see if I can explain better. If I do something like this:

 function rew(m:MovieClip, f:String {
m.onEnterFrame = function() {
var cf:Number = m._currentframe;
var tf:Number = m._totalframes;
if (cf=tf  cf1) {
m.gotoAndStop(--cf);
} else if (cf==1) {
m.stop();
if(f == play) play();
delete m.onEnterFrame;
}
};
 }

 it works perfectly, but I want to call any function and don't wanna
 have to
 make a switch for every kind o function.
 Has anyone got it?


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Passing a Function as Parameter and call function later

2007-02-18 Thread Wagner Amaral

I'm not testing, but you could use:

f.call();

as long as f is a reference to a Function object



On 2/18/07, Felipe Hefler [EMAIL PROTECTED] wrote:


Thank you dr.ache.

Wasn't that  the problem. Anyway your answer helped me a lot. See what
solution I came up:

function rew(m:MovieClip, f:Function) {
m.onEnterFrame = function() {
var cf:Number = m._currentframe;
var tf:Number = m._totalframes;
if (cf=tf  cf1) {
m.gotoAndStop(--cf);
} else if (cf==1) {
m.stop();
if(f) eval(f)();
delete m.onEnterFrame;
}
};
}

But the change was on the way I call the function:
_root.rew(d.mask,_root.nextFrame);

So now if I pass it between  it seems to work fine. But still, there's a
small problem that bothers me. Now I have to use eval(), wich I don't like
at all. Any Ideas on how changing eval to a better solution?



On 18/02/07, dr.ache [EMAIL PROTECTED] wrote:

 Hi.

 i guess you have a scope problem. for me, your code worked
 fine, here my adjustments to test it (i got one MC with a 180 frame
 MotionTween starting at 120 when loaded, on the stage, called fred.
 i simulated the function call with an interval, so the animation starts
 and
 after 2 seconds, your function rew is called with the parameters
 _root.fred and the function which should be called after rewind the
 animation sayHello.

 It works. When you use Flash 8, try to understand the Delegate Class,
 which should help you handle the scope problem.

 hope that helps...
 dr.ache

 var i:Number = setInterval(this,rew,2000,_root.fred,sayHello);

 function rew(m:MovieClip, f:Function) {
 clearInterval(_root.i);
m.onEnterFrame = function() {
var cf:Number = m._currentframe;
var tf:Number = m._totalframes;
if (cf=tf  cf1) {
m.gotoAndStop(--cf);
} else if (cf==1) {
m.stop();
if(f) f();
delete m.onEnterFrame;
}
};
 }

 function sayHello() {
 trace(hallo);
 }

 Felipe Hefler schrieb:
  Hi everyone! I'm having trouble with this issue:
  function rew(m:MovieClip, f:Function) {
 m.onEnterFrame = function() {
 var cf:Number = m._currentframe;
 var tf:Number = m._totalframes;
 if (cf=tf  cf1) {
 m.gotoAndStop(--cf);
 } else if (cf==1) {
 m.stop();
 if(f) f();
 delete m.onEnterFrame;
 }
 };
  }
 
  When I call this function in an action frame it's like this:
  rew(targetpath_movieClipName, _root.play);
 
  What I want is that the function I've passed as a parameter works like
a
  function later in the code. Messy explanation?? OK OK...
  Let's see if I can explain better. If I do something like this:
 
  function rew(m:MovieClip, f:String {
 m.onEnterFrame = function() {
 var cf:Number = m._currentframe;
 var tf:Number = m._totalframes;
 if (cf=tf  cf1) {
 m.gotoAndStop(--cf);
 } else if (cf==1) {
 m.stop();
 if(f == play) play();
 delete m.onEnterFrame;
 }
 };
  }
 
  it works perfectly, but I want to call any function and don't wanna
  have to
  make a switch for every kind o function.
  Has anyone got it?
 

 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Passing a Function as Parameter and call function later

2007-02-18 Thread Felipe Hefler

I've tried it, and didn't work. Can you say how this reference should be?

On 18/02/07, Wagner Amaral [EMAIL PROTECTED] wrote:


I'm not testing, but you could use:

f.call();

as long as f is a reference to a Function object



On 2/18/07, Felipe Hefler [EMAIL PROTECTED] wrote:

 Thank you dr.ache.

 Wasn't that  the problem. Anyway your answer helped me a lot. See what
 solution I came up:

 function rew(m:MovieClip, f:Function) {
 m.onEnterFrame = function() {
 var cf:Number = m._currentframe;
 var tf:Number = m._totalframes;
 if (cf=tf  cf1) {
 m.gotoAndStop(--cf);
 } else if (cf==1) {
 m.stop();
 if(f) eval(f)();
 delete m.onEnterFrame;
 }
 };
 }

 But the change was on the way I call the function:
 _root.rew(d.mask,_root.nextFrame);

 So now if I pass it between  it seems to work fine. But still, there's
a
 small problem that bothers me. Now I have to use eval(), wich I don't
like
 at all. Any Ideas on how changing eval to a better solution?



 On 18/02/07, dr.ache [EMAIL PROTECTED] wrote:
 
  Hi.
 
  i guess you have a scope problem. for me, your code worked
  fine, here my adjustments to test it (i got one MC with a 180 frame
  MotionTween starting at 120 when loaded, on the stage, called fred.
  i simulated the function call with an interval, so the animation
starts
  and
  after 2 seconds, your function rew is called with the parameters
  _root.fred and the function which should be called after rewind the
  animation sayHello.
 
  It works. When you use Flash 8, try to understand the Delegate Class,
  which should help you handle the scope problem.
 
  hope that helps...
  dr.ache
 
  var i:Number = setInterval(this,rew,2000,_root.fred,sayHello);
 
  function rew(m:MovieClip, f:Function) {
  clearInterval(_root.i);
 m.onEnterFrame = function() {
 var cf:Number = m._currentframe;
 var tf:Number = m._totalframes;
 if (cf=tf  cf1) {
 m.gotoAndStop(--cf);
 } else if (cf==1) {
 m.stop();
 if(f) f();
 delete m.onEnterFrame;
 }
 };
  }
 
  function sayHello() {
  trace(hallo);
  }
 
  Felipe Hefler schrieb:
   Hi everyone! I'm having trouble with this issue:
   function rew(m:MovieClip, f:Function) {
  m.onEnterFrame = function() {
  var cf:Number = m._currentframe;
  var tf:Number = m._totalframes;
  if (cf=tf  cf1) {
  m.gotoAndStop(--cf);
  } else if (cf==1) {
  m.stop();
  if(f) f();
  delete m.onEnterFrame;
  }
  };
   }
  
   When I call this function in an action frame it's like this:
   rew(targetpath_movieClipName, _root.play);
  
   What I want is that the function I've passed as a parameter works
like
 a
   function later in the code. Messy explanation?? OK OK...
   Let's see if I can explain better. If I do something like this:
  
   function rew(m:MovieClip, f:String {
  m.onEnterFrame = function() {
  var cf:Number = m._currentframe;
  var tf:Number = m._totalframes;
  if (cf=tf  cf1) {
  m.gotoAndStop(--cf);
  } else if (cf==1) {
  m.stop();
  if(f == play) play();
  delete m.onEnterFrame;
  }
  };
   }
  
   it works perfectly, but I want to call any function and don't wanna
   have to
   make a switch for every kind o function.
   Has anyone got it?
  
 
  ___
  Flashcoders@chattyfig.figleaf.com
  To change your subscription options or search the archive:
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
  Brought to you by Fig Leaf Software
  Premier Authorized Adobe Consulting and Training
  http://www.figleaf.com
  http://training.figleaf.com
 
 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com