Adding a CallBack Function - SWiSHMax Tutorials
 
  Buy Ebooks, Video Games, DVDs, Electronics and more !
Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads Make Money Online Blog . Free Image and Photo Sharing and Hosting

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Free image hosting
   Web Design Pakistan
   Swish Templates
   SWiSH Climax
   Talkfreelance Community
   Template Desire
   Lite boards
   Script Sector
   GimpTalk
   13dots
   Idea Designs
   PHP Cafe
   Sposatoettore
   Free swishmax templates
   Swishzone

Manage your site with Flax Article Content Management System
Adding a CallBack Function
Category : SWiSHMax | Level : Intermediate | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

Adding a CallBack Function - Why and How by example.

You might like to review the original example first: .: POST :.

CallBack
A callback function is one that is not invoked explicitly by the programmer; rather the responsibility for its invocation is delegated to another function that receives the callback function's reference and instructions as to when to run the callback function.

Ouch! ...one might say. But not really.
It is the basis (sort-of) for understanding events: when this happens, do whatever is in this function.

In this fade in/out example, we may want to fade an image in and then do something else like start several place effects for other movie components. Or fade one image out and immediately fade another image in.

Not to get carried away, lets start simple and say after the fade-in/out let's simply pop-up an alert box.

So first we define a CallBack function, say cbFunc, to generate a simple JavaScript alert to say, "Done..."

In SWiSH, I define functions in the onLoad code sections like:
var cbFunc = function( name, type ) {
javascript( "alert('Done: "+name+" faded"+type+"');" );
};


Now, in our fader code, where would we want to invoke this pop-up?
Well certainly, when the fade-in/out has just completed. And in our code that is inside the setInterval loop, just after we stop the interval loop itself.

So, two changes to the prototype code:
1) add a parameter to pass the CallBack function reference:
MovieClip.prototype.rgbFade=function(type,func){
2) the code to call this function, if it was provided:
clearInterval(self.rgbIntervalID);
if(func) func(self._name, self.type);
delete self.rgbIntervalID;


And on our buttons:
Image.rgbFade( "In", cbFunc );
Image.rgbFade( "Out", cbFunc );


Note that if we do not supply the CallBack function:
Image.rgbFade( "In" );
...it works as before, no problem.

Example: .: LINK :.

Download Source

gsb


© 2002-2005 Flaxweb Network | Article Manager | Gimp Tutorials Library | RAD C++ Library | Free C/C++ Sourcecode |
Sites of interest : Web Design Blog | Swish Templates | Swishmax Ebook | Photoshop Templates | Gimp Tutorials | Text Forum | Make Money Online