Hok's Macromedia Flash Blog

macromedia flash actionscript scripting, php, remoting, webservices, c#, javascript

Ads

Search

AS2: user-class-mc and attachMovie - nice trick...

...for calling the init-method automagicly(implicit) under usage of the init-object.



I found this trick in the german flashforum where Florian Krüsch, a great and creative developer, postet this trick.

The idea is very simple:

  • We attach a movie, and using the init-object param of attachMovie.

  • Within we define an initParams-field.

  • The magic is, that now implicitly a setter is called for the initParams-field.

  • This setter just call our init.

This idea is so cool, thank you Mister Krüsch...;-)
class ExtendedMc extends MovieClip
{
   public function ExtendedMc()
   {

   }

   private function init(a,b,c:String):Void
   {
      trace([a,b,c]);
   }

   public function set initParams(initValArr:Array):Void {
      init.apply(this,initValArr);
   }
}
// FLA:
_root.attachMovie("ExtendedMc", "m", 100, {initParams:["Horst","Peter","Gustav"]});

Posted by hOk at January 27, 2004 09:55 AM

Comments (3)

you´re welcome :D

Posted by Florian Krüsch at January 28, 2004 10:46 AM

:D

Posted by hOk at January 28, 2004 11:01 AM

A really cool tuff idea Mister Krüsch. Thank´s hOk for the details .

Posted by mabo at January 29, 2004 01:31 PM


Name:


Email Address:


URL:


Comments:



You can use <code>code that should be highlightned</code> to highlight code!
Optionally you can use the attribut language="php|perl|java" within the code tag, otherwise
actionscript-highlightning will be used.

New Place