3 Replies Latest reply on Sep 4, 2006 4:43 AM by tiandike

    How to use MovieClip class

    tiandike
      How to display the MovieClip in the stage?
        • 1. How to use MovieClip class
          tiandike Level 1
          My code doesn't work,how to modify?
          my code is :
          package com.example.programmingas3.mc
          {
          import flash.display.MovieClip;
          import flash.text.TextField;
          import mx.core.UIComponent;

          public class MovieClipExample extends UIComponent {

          public var mc:MovieClip;

          public function MovieClipExample() {
          mc=new MovieClip();
          var outputText:TextField = new TextField();
          outputText.text = getPropertiesString();
          outputText.width = 100;
          outputText.height = 30;
          mc.addChild(outputText);

          }

          private function getPropertiesString():String {

          var str:String = ""
          + "currentFrame: " + mc.currentFrame + ","
          + "currentLabel: " + mc.currentLabel + ","
          + "currentScene: " + mc.currentScene + ","
          + "framesLoaded: " + mc.framesLoaded + ","
          + "totalFrames: " + mc.totalFrames + ","
          + "trackAsMenu: " + mc.trackAsMenu + ",";
          return str;

          }
          }
          }


          my mxml code is :
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          xmlns:example="com.example.programmingas3.mc.*"
          xmlns="*"
          paddingTop="0"
          width="100%"
          height="100%"
          layout="vertical" >
          <mx:Panel width="550" height="400" layout="absolute">


          <example:MovieClipExample id="myMovie" width="500" height="300" >

          </example:MovieClipExample>

          </mx:Panel>

          </mx:Application>
          • 2. Re: How to use MovieClip class
            peterent Level 2
            Your example isn't following the Flex framework which is why it is not working correctly. Even though are extending a class, you still have to override the correct functions. Use createChildren() to make your child; making it in the constructor is OK, but adding the child to the UIComponent in the constructor will not work as the framework hasn't set it up yet.

            You can read about this in the Flex 2 documentation on creating custom ActionScript components.

            Also: you added the TextField to the MovieClip but did not add the MovieClip to the UIComponent. From what I can you are doing, don't bother with TextField or MovieClip, just use mx.controls.Text.
            • 3. Re: How to use MovieClip class
              tiandike Level 1
              the code below is from the flex2 help ,but how to use this code?

              package {
              import flash.display.MovieClip;
              import flash.text.TextField;

              public class MovieClipExample extends MovieClip {

              public function MovieClipExample() {
              var outputText:TextField = new TextField();
              outputText.text = getPropertiesString();
              outputText.width = stage.stageWidth;
              outputText.height = outputText.textHeight;
              addChild(outputText);
              }

              private function getPropertiesString():String {
              var str:String = ""
              + "currentFrame: " + currentFrame + "\n"
              + "currentLabel: " + currentLabel + "\n"
              + "currentScene: " + currentScene + "\n"
              + "framesLoaded: " + framesLoaded + "\n"
              + "totalFrames: " + totalFrames + "\n"
              + "trackAsMenu: " + trackAsMenu + "\n";
              return str;
              }
              }
              }