Original: http://www.flashandmath.com/flashcs4/leo/index.html
Let's introduce a custom AS3 class, Imageaccordion, to fold and unfold the picture like an accordion. We use the 3D method of FlashPlayer10 native, and the effect is very realistic. When clicked, the picture is folded or expanded in the form of a motion tween.
Next, let's discuss the Imageaccordion class, which is the core of the effect.
Using the Imageaccordion class
What did you see in the show above? Two Imageaccordion class instances, one instance per image.
The Imageaccordion class extends from Sprite. Its constructor has four parameters, one required, and three optional
- New Imageaccordion (bd:bitmapdata,df:number=0.5, lf:number=0, sl:int=10)
Copy Code The first parameter is the BitmapData object of the picture, you can import the picture into the library and use the AS3 link, either through Flex or at runtime (loading).
The values of
"DF" and "LF" are passed to the "Darkedgefactor" and "Lightedgefactor" properties in the class. These values determine the darkness of the bottom edge and the brightness of the top edge. "DF" preferably between 0-1, the greater the DF value is darker. Likewise "LF" is preferably also between 0-1. The larger the number, the brighter it is. The default setting corresponds to a picture with a good luminance. The last parameter is the number of folds of the accordion.
in the sample FLA file, we use the graph in the library, which establishes the link through AS3, and the class name is Leonardo and Monalisa respectively. Then we create two imageaccordion, one for each image. Here is the code for creating the first instance on the timeline (the Flashandmath folder in the Zip package is in the same folder as your FLA file so that the Imageaccordion class can be found)
- Import flashandmath.as3.ImageAccordion;
- var accordion:imageaccordion=new imageaccordion (New Leonardo (224,350), 0.5,0,14);
- This.addchild (accordion);
- accordion.x=160;
- accordion.y=235;
Copy Code
We rotate the first instance-30 degrees, Z coordinates to 100, so it becomes smaller and clearer.
Next we do the same thing with the Mona Lisa, just put her on the right and rotate it 30 degrees.
The text you see on the stage is written dead in Flash. Of course, you can also use dynamic text to load other content from the outside at run time. The Imageaccordion class has two public properties: Tweendownduration and Tweenupduration. They default to 50 and 40. You can easily change their values, such as setting:
accordion.tweenupduration=20;