[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why doesnt my AS3 MovieClip show

Posted on 2011-04-27
5
Medium Priority
?
517 Views
Last Modified: 2012-05-11
I'm just trying to show a movieclip (that i draw in code) on the stage but it doesnt appear.
Here's my code:
(this is my class referenced from the FLA)ie. the class in the "Class" field of "Publish" details.
Every thing else i put in here works so it's not my class and fla syntax that doesnt work.

      public class CBitmap2 extends MovieClip
      {
            protected var m_spTest:MovieClip;

            public function CBitmap2()
            {
                  m_spTest = new MovieClip();
                  m_spTest.x = 50;
                  m_spTest.y = 50;
                  m_spTest.width = 100;
                  m_spTest.height = 100;
                  m_spTest.graphics.beginFill( 0xff00ff );
                  m_spTest.graphics.drawRect(0, 0, 100, 100);
                  m_spTest.graphics.endFill();                  
                  m_spTest.visible = true;
//Now i try 3 ways but none work
                  parent.addChild(m_spTest);
                  this.addChild(m_spTest);
                  addChild(m_spTest);
            }
      }
0
Comment
Question by:jasonb2
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35480974
Try the following:
public class CBitmap2 extends MovieClip
      {
            protected var m_spTest:MovieClip;

            public function CBitmap2()
            {
                  addEventListener(Event.ADDED_TO_STAGE, on stageAddedHandler, false, 0, true );
            }

            private function stageAddedHandler():void
            {
                  removeEventListener(Event.ADDED_TO_STAGE, on stageAddedHandler );

                  m_spTest = new MovieClip();
                  m_spTest.x = 50;
                  m_spTest.y = 50;
                  m_spTest.width = 100;
                  m_spTest.height = 100;
                  m_spTest.graphics.beginFill( 0xff00ff );
                  m_spTest.graphics.drawRect(0, 0, 100, 100);
                  m_spTest.graphics.endFill();                  
                  m_spTest.visible = true;
                  addChild(m_spTest);
            }
      }

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:jasonb2
ID: 35481030
thanks, but it didnt work.
0
 

Accepted Solution

by:
jasonb2 earned 0 total points
ID: 35481157
ok, I've got it working now. I had to remove the following lines:
      m_spTest.width = 100;
      m_spTest.height = 100;
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35481165
Kindly place a trace in the method stageAddedHandler() for stage.

trace(stage);

Let me know what it show.

Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:jasonb2
ID: 35503496
This works now
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question