We love choice

Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://fxr.groups.adobe.com.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

3D, ActionScript, How to

How To Use FIVe3D In Flex

Andrei Ionescu | 17.06.08 | 9 Comments

Table of contents

  1. How To Use FIVe3D In Flex
  2. How To Use FIVe3D And Tweening in Flex
Google Buzz

For some time I’ve been planning to use FIVe3D of Mathieu Badimon, in Flex, not in Flash. I’ve been trying to make it work but no success ’till now.

After more than 4, 5 tries, I’ve managed to take the example from the FIVe3D framework and implemented it in Flex. It was not an easy task because of some compile errors, regarding the missing fl.motion package. What I found out is that fl.motion package is included in Flash CS3 but not into Flex framework and although FIVe3D is AS3 is not fully compatible with Flex framework (see it in livedocs).

What I did to make it work?

  1. Downloaded the FIVe3D framework from five3d.mathieu-badimon.com. Sometimes the site is not working and the user is redirected to 404.online.net.
  2. Created a new Flex Project and copied the whole five3D folder (with display, geom, typography and utils) from the archive into it.
  3. Taken the Main.as file from first_example folder and started copying lines into my new project
  4. Commented out the lines of code from (commented where fl.motion is used):
    • Shape3D.as – line 17 and from line 279 to 282
    • Sprite3D.as – line 18 and from line 302 to 306
    • Bitmap3D.as – line 21 and from line 477 to 480

My FIVe3D example is bellow (working application and code).

You can click on the rounded square to rotate it randomly.
 

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    backgroundGradientColors="[#dddddd,#dddddd]"
    layout="absolute" 
    width="500"
    height="500"
    creationComplete="start()">
    <mx:UIComponent id="mainUI"/>
    <mx:Script>
        <![CDATA[
            import five3D.typography.HelveticaBold;
            import five3D.utils.Drawing;
            import five3D.display.Scene3D;
            import five3D.display.DynamicText3D;
            import five3D.display.Shape3D;
            import five3D.display.Sprite3D;
 
            private var scene3D:Scene3D;
            private var sprite3D:Sprite3D;
            private var star3d:Shape3D;
            private var flexerWord:DynamicText3D;
            private var hiWord:DynamicText3D;
 
            // start drawing
            private function start():void
            {
                // create the scene
                scene3D = new Scene3D();
                scene3D.x = 250;
                scene3D.y = 250;
                // create the round rectangle/square
                sprite3D = new Sprite3D();
                sprite3D.graphics3D.beginFill(0x000000);
                sprite3D.graphics3D.drawRoundRect(-150, -150, 300, 300, 40, 40);
                sprite3D.graphics3D.endFill();
                // rotate the round rectangle/square randomly
                sprite3D.rotationX = Math.random()*100-50;
                sprite3D.rotationY = Math.random()*100-50;
                sprite3D.rotationZ = Math.random()*100-50;
                // create the star
                star3d = new Shape3D();
                Drawing.star(star3d.graphics3D, 20, 60, 50, 0, 0x6699cc);
                star3d.x = 120;
                star3d.y = -80;
                // rotate the start
                star3d.addEventListener(Event.ENTER_FRAME,
                    function (event:Event):void {
                        // rotate on Z axe 
                        event.target.rotationZ++; 
                    }
                );
                // "fxr" word
                flexerWord = new DynamicText3D(HelveticaBold);
                flexerWord.size = 45;
                flexerWord.color = 0xFFFFFF;
                flexerWord.text = "Fxr";
                flexerWord.x = 88;
                flexerWord.y = -110;
                // "hi" word
                hiWord = new DynamicText3D(HelveticaBold);
                hiWord.size = 100;
                hiWord.color = 0x555555;
                hiWord.text = "Hi!";
                hiWord.x = -112;
                hiWord.y = -34;
                // click event on the round rectangle/square
                sprite3D.addEventListener(MouseEvent.CLICK, 
                    function(event:MouseEvent):void
                    {
                        // rotate the round rectangle/square randomly
                        // all 3 axes
                        event.target.rotationX = Math.random()*100-50;
                        event.target.rotationY = Math.random()*100-50;
                        event.target.rotationZ = Math.random()*100-50;
                    }
                );
                sprite3D.mouseChildren = false;
                sprite3D.buttonMode = true;
                // adding scene to the main UI component
                mainUI.addChild(scene3D);
                // adding round rectangle/square to the scene
                scene3D.addChild(sprite3D);
                // adding the start to the round rectangle/square
                sprite3D.addChild(star3d);
                // adding "fxr" word to the round rectangle/square
                sprite3D.addChild(flexerWord);
                // adding "hi" word to the round rectangle/square
                sprite3D.addChild(hiWord);
            }
        ]]>
    </mx:Script>
</mx:Application>

The FIVe3D framework is simple and is seems to draw very fast. What can be the next step: using tweening with FIVe3D in Flex.

Some related resources:
http://labs.vizar.de/blog/2008-05-12/first-steps-with-five3d/
http://tech.nitoyon.com/blog/2008/05/keynote_like_cube_transition.html

Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites
five3d
five3d_sources




Tags: , ,

This post was written by Andrei Ionescu

Views: 18284

related

9 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


«
»