7 Replies Latest reply on Aug 5, 2010 8:22 PM by slugger_2003

    Creating a 3D dice/clock

    slugger_2003

      Hi all,

       

      I am trying to create a dice that doubles up as a 60 second timer that counts from 60 to 0. I have managed to create the timer with some actionscript and a single frame swf, one layer for the AS 3 and one for the dynamic text box. I have also create a die from four 60*60 squares that animates 90 degree's so it looks as if it is rolling.

      My issue is, how do I bring these together? As the clock/timer is dynamic textbox it can't be animated around 3D space, so it needs to be converted into a movie clip (to the best of my knowledge). when I do this, the actionscript no longer works as it's no longer having to update the text attribute of a textfield, but the contents of a movieclip.

      Next, I tried to import the timer.swf (clock) and dice.swf with the Loader class and loaded each of them into a movieclip, then layered them. This ALMOST works, however unlike the text in timer.swf, the text in this instance is not refreshed and simply writes the updated value over the previous value.

      Here is what I've ended up with:

       

      AS 3 code:

       

      <code>

       

      var dice:Loader = new Loader();

      var newTime:Loader = new Loader();

       

      dice.load(new URLRequest("SWFs/dice.swf"));

      die_mc.addChild(dice);

      die_mc.x=200;

      die_mc.y=150;

       

      newTime.load(new URLRequest("SWFs/timer.swf"));

      clock_mc.addChild(newTime);

      clock_mc.x=200;

      clock_mc.y=150;

      addChild(clock_mc); //need to do this or the time is not displayed in front of the die

      </code>

       

      The main issue is the text not refreshing and overwriting the previous number, here is a video of the issue:

       

       

      There doesn't appear to be an issue with the timer or the cube in the original SWF's, ignore the first few seconds of the clip (when it skips from 42  to 60), I had to reset the recording software, here is the timer:

       

        • 1. Re: Creating a 3D dice/clock
          slugger_2003 Level 1

          bump - Anyone?

          • 2. Re: Creating a 3D dice/clock
            Ned Murphy Adobe Community Professional & MVP

            Based on the first video, somewhere along the the line the timer or its textfield are being duplicated.  The code you show won't do that unless you have it operating in some form of loop, either a coded loop or a timeline loop.

            • 3. Re: Creating a 3D dice/clock
              slugger_2003 Level 1

              I can't see where it could be duplicated.....

               

              Here is the code for the timer:

               

              //initial value of clock

              var mySecs:int=61;

              // Updates clock every second. Insert 2000 to check every 2 seconds.

              var myTimer:Timer=new Timer(1000,mySecs);

              var myDate:Date;

              var secsStr:String;

              myTimer.addEventListener(TimerEvent.TIMER, timerHandler);

              myTimer.start();

               

               

              function timerHandler(event:TimerEvent):void

              {

                   time_txt.text = String((mySecs)-myTimer.currentCount);

                   if (mySecs==0)

                   {

                   myTimer.stop();

                   myTimer.removeEventListener(TimerEvent.TIMER, timerHandler);

                   }

              }

               

               

              A screen shot of the timeline:

               

              ScreenShot001.png

               

              As the timer is only one frame long, it does inherently loop until mySecs==0.

              At this stage, the timer is a dynamic textfield, not a movieclip.

               

              In an attempt to break this down a little, I have created a new project where I have created a movieclip called timer then created a new instance of this object called clock_mc on the stage. The object is a 60*60 square that I created, with the intention of using it as a container for the timer so I could animate the timer, as the timer is a dynamic text field, which to the best of my knowledge, cannot be 3D animated. As the timer is meant to layer on top of the die, it is required to animate in 3D like the die does.

               

              Here is the AS3 that I used:

               

              var newTime:Loader = new Loader();

               

              newTime.load(new URLRequest("SWFs/timer.swf")); //This is the SWF created above that consists of a single framed SWF that counts from 60 to 0                                                                                  //as seen above

              clock_mc.x=200;

              clock_mc.y=150;

              clock_mc.addChild(newTime);

               

              Here is the result:

               

               

              The timer does not appear inside the moveclip??? If I change the x and y co-ords of clock_mc it does move independently  of where it is originally located on the stage, as you would expect, however the timer ends up diagonally below timer_mc at a constant distance....So even if the movieclip did animate, the text wouldn't be animating inside it! I'm mightily confused....can SWF's not be loaded into movieclips in this manner? If not...any suggestions on how I should approach this?

              • 4. Re: Creating a 3D dice/clock
                slugger_2003 Level 1

                Update: In case anyone else finds themselves in a similar scenario....ensure your vanishing points line up. Mine do now and the above movieclip/dynamic textbox alignment issue is solved. The size of the stage doesn't appear to make any difference in either instance:

                 

                Incorrect alignment:

                 

                ScreenShot003.png

                 

                Correct alignment:

                 

                ScreenShot002.png

                • 5. Re: Creating a 3D dice/clock
                  slugger_2003 Level 1

                  So after playing about with this for a while, this is what I have for the timer:

                   

                   

                  This is the AS3:

                   

                  var newTime:Loader = new Loader();

                   

                  newTime.load(new URLRequest("SWFs/timer.swf"));

                  clock_mc.addChild(newTime);

                   

                  The AS3 for timer.swf is in my previous posts.

                   

                  And this is the timeline:

                   

                  ScreenShot004.png

                  I don't understand why the timer works fine when it is being implemented as a dynamic text box but not as a move clip....Can anyone suggest a way that will allow me to get this timer to update like it does when it's a dynamic text box and animate like it does when it's a movie clip? It works fine as a movie clip until I try to animate it...

                  • 6. Re: Creating a 3D dice/clock
                    slugger_2003 Level 1

                    After continuous strain this problem still persists....Updating the text in the dynamic text box works fine. Importing this into a movieclip, works fine. When the movie clip that contains the dynamic text is animated...it blows it's guts....WHY?!!! Have I stumbled upon the limits of flash in this context or am I doing something wrong....just knowing would be enough....