Flash CS3: Create a reflex effect on any MovieClip

Taking advantage of a remarkable feature of Actionscript 3.0 (see ActionScript 3.0, all with the new operator ) I created a class ReflexMe able to generate an effect "reflection" on any MovieClip present in the library.

Loading Flash ...

The source is part of the package undolibrary - GoogleCode of this - but if you want you can download the single file ReflexMe.as .


Utilization

Download the file ReflexMe.as and place it in the folder of your movie. fla. Select the MovieClip in the library to which you want to apply the effect reflex and open the properties window symbol. In the Linkage section ReflexMe included in base class:

MovieClip

At this point, feeling the movie, the MovieClip selected will have the effect of SLR. If given the MovieClip an instance name potrente also adjust parameters such as:

  • reflexOffset - distance of the reflection
  • gradientOffset - reflected the extension of the gradient
  • alphaOffset - alpha channel of the reflection
  • gradientRadial - kind of reflection: radial or linear

Notes

The class ReflexMe.as is written as a base class to extend any MovieClip. Its simplicity is such that you can riaddatarla and disarming code as "spurious" to be used by code, rather than Flash IDE. The whole effect is generated by the few (comments removed) lines of code that follow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/ / Preserve the original large holdall of MovieClip
width ; __oWidth = this. width;
height ; __oHeight = this. height;
/ / Create a BitmapData of the large holdall
/ / MovieClip to which I apply the effect reflex
( this . width , this . height , true , 0x000000 ) ; __bmpd = new BitmapData (this. width, this. height, true, 0x000000);
/ / I copy the BitmapData on MovieClip
( this ) ; __bmpd. draw (this);
/ / Create a Bitmap object to display
/ / This will effect our SLR
( __bmpd ) ; __bmp = new Bitmap (__bmpd);
/ / Not see that
__bmp ) ; addChild (__bmp);
/ / Rotate it 180 degrees: the invert
= - 1 ; __bmp. scaleY = - 1;
/ / Position it at the base of the MovieClip oroginale
/ / The 2 x the height is necessary for the result of chance
/ / Rotation that has shifted the origin of the axes
= __oHeight * 2 + __reflexOffset ; __bmp. __oHeight = y * 2 + __reflexOffset;
/ / Cached as a bitmap: need to cover up after
/ / With gradient effect and alpha channel
= true ; __bmp. cacheAsBitmap = true;
/ / Create a mask
( ) ; __mask = new Shape ();
/ / Cached as a bitmap: need to cover up after
/ / With gradient effect and alpha channel
= true ; __mask. cacheAsBitmap = true;
/ / Position it also reflected on the image
= __oHeight + __reflexOffset ; __mask. __oHeight = y + __reflexOffset;
/ / Create a matrix for the gradient
( ) ; __matrix = new Matrix ();
/ / Create the gradient of the same size
/ / Original MovieClip
( __oWidth , __oHeight , Math . PI / 2 ) ; __matrix. createGradientBox (__oWidth, __oHeight, Math . PI / 2);
__mask . graphics ) { with (__mask. graphics) {
; clear ();

0 , 0 , __oWidth , __oHeight ) ; drawRect (0, 0, __oWidth, __oHeight);
; endFill ();
}
__mask ) ; addChild (__mask);
/ / Set mask
= __mask ; __bmp. __mask = mask;

17 comments to "Flash CS3: Create a reflex effect on any MovieClip"

  1. June 5, 2008 Mark:

    Hello I have tried to use this class but I get errors.

    I tell you the procedure I did, so maybe you can tell me whether and where wrong.

    Nuon-create a document in as3,
    -Drawing a simple square, and turned it into movie clip;
    -Right click on the symbol in the library, in the Linkage section ReflexMe insert in base class;
    -I saved the file logically fla in the same folder where ReflexMe.as

    But give me these errors:
    1017-error can not find the definition of base class ReflexMe;
    -5000: The class 'ReflexMe' must be a subclass of 'flash.display.MovieClip' because it is linked to a library symbol of that type;
    -5001: The package name 'undolibrary.sfx' does not reflect the position of the file. Change the name of the package definition in the file or move the file. C: \ Documents and Settings \ User \ Desktop \ ReflexMe.as

    What's wrong? What should I do?
    I thank you in advance.
    Hello!

  2. June 5, 2008 Giovambattista Fazioli :

    @ Mark: if you use the file ReflexMe.as outside the library undolibrary you change the "namespace" of the package. At the beginning of the file are "undolibrary.sfx package", delete the namespace "undolibrary.sfx", with leaves only "package {" - with the clip :)

  3. 13 June 2008 Reflex and ReflexMe: on the basis of class Class | Undolog.com :

    [...] Post Flash CS3: Create a reflex effect on any MovieClip we saw how you can write a class that extends MovieClip, to connect it to [...]

  4. July 9, 2008 Linus:

    Congratulations on your wonderful website. I wanted to know if I named my movieclip instance how can I access the properties reflexOffset etc..
    Thanks

  5. July 10, 2008 Giovambattista Fazioli :

    @ Linus: You can use miaistanza.reflexOffset to access all the properties. When you use the class Reflex extend, in fact, the basic characteristics of the MovieClip. This means that the MovieClip gets all the properties and methods of the Reflex .

  6. August 3, 2008 carlitos:

    Hello to all who are reading my message. I wanted to ask some of you, if I insegnaste how to create submenus on flash cs3. I searched the internet, but I do not know how to do it. Please could you help me? My contact is: sicilianofolle@hotmail.it
    expect many thanks!

  7. August 4, 2008 Giovambattista Fazioli :

    @ Carlitos: exactly what you need?

  8. March 8, 2010 alberto:

    @ Giovambattista Fazioli:
    1017: Can not find the definition of base class SLR.
    5000: The class 'ReflexMe' must be a subclass of 'flash.display.MovieClip' because it is linked to a library symbol of that type.
    are the errors in an attempt help please
    by alberto

  9. March 8, 2010 Giovambattista Fazioli :

    @ Alberto: you must place the class SLR (spot. Pbuh) in the same folder as your. Fla

  10. March 8, 2010 alberto:

    @ Giovambattista Fazioli: of course it was already positioned in the same folder as my fla.

  11. March 8, 2010 Giovambattista Fazioli :

    @ Alberto: Changes the start of class:

    1
    sfx { undolibrary package. sfx {

    just in:

    1
    package {
  12. March 8, 2010 alberto:

    @ Giovambattista Fazioli: I had already done the same results

  13. August 21, 2011 Luke:

    Alberto in the same situation ... does not work!

  14. August 21, 2011 Luke:

    That is, if you see the code reflexMe.as you posted does not say anything in embankments
    In my opinion you have failed to write the article

  15. August 30, 2011 Giovambattista Fazioli :

    @ Luke: No, the code and the article are not wrong. The problem is the inclusion of the library undolibrary . Read here for details

  16. August 30, 2011 Luke:

    oh well, you said that was enough to download reflexMe.as

    cm ² in the meantime I found another class that creates the reflection effect and works well even with animated MC

  17. August 31, 2011 Giovambattista Fazioli :

    @ Luke: could actually be mistaken. In fact this class is based (ie, wants) on the library undolibrary . If you already have installed, you can download only the files indicated, otherwise if you download the latest version you can find everything in the package.

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL