Skip to main content
Inspiring
December 3, 2009
Answered

How to add a movie to the stage

  • December 3, 2009
  • 3 replies
  • 980 views

The code below is used to make a slideshow. It works as long as I load my content into container_mc. container_mc is a movieclip that is created on the stage and it contains a simple shape for a background.

Instead of creating the movieclip on the stage I want to generate the movieclip dynamically as follows:

            container_mc1=new MovieClip;
             container_mc1.width=100;
             container_mc1.height=100;
             s=new Shape;
             container_mc1.addChild(s);
             this.addChild(container_mc1);

However, the movieclip does not seem to be added to the stage. It does not work when I uncomment the line:

//slideView = new SlideshowView(container_mc1);

How should I connect container_mc1 to the stage? Thank you!

package{
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import mvc.SlideshowModel;
    import mvc.SlideshowView;
   
    public class SlideshowDocument extends MovieClip{
        private var slideModel:SlideshowModel;
        private var slideView:SlideshowView;
        private var req:URLRequest=new URLRequest("data.xml");
        private var container_mc1:MovieClip;
        private var s:Shape;
        public function SlideshowDocument(){
            container_mc1=new MovieClip;
            container_mc1.width=100;
            container_mc1.height=100;
            s=new Shape;
            container_mc1.addChild(s)
            this.addChild(container_mc1)
            slideView = new SlideshowView(container_mc);
            //slideView = new SlideshowView(container_mc1);
            slideModel = new SlideshowModel();
            slideView.model = slideModel;
            slideModel.load(req);
        }
    }
}

This topic has been closed for replies.
Correct answer kglad

oops, you need a linestyle or fill.  in addition, you should (not) set a width/height on an empty object:


package{
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import mvc.SlideshowModel;
    import mvc.SlideshowView;
   
    public class SlideshowDocument extends MovieClip{
        private var slideModel:SlideshowModel;
        private var slideView:SlideshowView;
        private var req:URLRequest=new URLRequest("data.xml");
        private var container_mc1:MovieClip;
        private var s:Shape;
        public function SlideshowDocument(){
            container_mc1=new MovieClip;
           // container_mc1.width=100;
            //container_mc1.height=100;

container_mc1.graphics.lineStyle(1);
            container_mc1.graphics.drawCircle(0,0,200);
            slideView = new SlideshowView(container_mc);
            //slideView = new SlideshowView(container_mc1);
            this.addChild(container_mc1)
            slideModel = new SlideshowModel();
            slideView.model = slideModel;
            slideModel.load(req);
        }
    }
}

3 replies

SiHoopAuthor
Inspiring
December 3, 2009

Just to document the problem:

I also had a problem from the following two lines:

            container_mc1.width=100;
            container_mc1.height=100;

It seems that sizing the object before any content has been added causes problems.

kglad
Community Expert
Community Expert
December 3, 2009

that's what i said. 

oops again, that's what i should have said.  (i omitted (not) in my pre-edited message.)

jsloop
Known Participant
December 3, 2009

you are creating movieclip and setting all properties for container_mc1

and you comment it out. And adds new statement with container_mc.

This should work.

package{
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import mvc.SlideshowModel;
    import mvc.SlideshowView;
   
    public class SlideshowDocument extends MovieClip {
        private var slideModel:SlideshowModel;
        private var slideView:SlideshowView;
        private var req:URLRequest=new URLRequest("data.xml");
        private var container_mc1:MovieClip;
        private var s:Shape;

        public function SlideshowDocument()
        {
            container_mc1=new MovieClip;
            container_mc1.width=100;
            container_mc1.height=100;
            s=new Shape;
            container_mc1.addChild(s);
            this.addChild(container_mc1);
            //slideView = new SlideshowView(container_mc);
           slideView = new SlideshowView(container_mc1);
            slideModel = new SlideshowModel();
            slideView.model = slideModel;
            slideModel.load(req);
        }
    }
}
SiHoopAuthor
Inspiring
December 3, 2009

I understand what you mean, but this does not work. In the code I posted I was showing the code that does work-- as soon as I swap the comment between the movieclip on the stage and my dynamically generated movieclip, it fails.

There must be something else that is missing, but I cannot see it!

SiHoopAuthor
Inspiring
December 3, 2009

Perhaps answering the following question will clarify the larger problem: Why won't the following code attach the movieclip and the Shape to the stage?

package{
    import flash.display.*;
   
    public class SlideshowDocument extends MovieClip{
        private var container_mc1:MovieClip;
        private var s:Shape;
        public function SlideshowDocument(){
            container_mc1=new MovieClip;
            s=new Shape();
            container_mc1.width=100;
            container_mc1.height=100;
            s.graphics.beginFill(0x00ff00)
            s.graphics.drawRect(0,0,100,100);//drawCircle(0,0,200);
            container_mc1.addChild(s);
            this.addChild(container_mc1)
        }
    }
}

kglad
Community Expert
Community Expert
December 3, 2009

if SlideshowDocument is your document class, container_mc1 is added to the stage when you use:

this.addChild(container_mc1);

from your document class.  because it has no visible content, you won't see anything.  adding s to container_mc1 adds no visible content.  (nowhere in your shown code do you do anything with container_mc.)

if you did something like:

container_mc1=new MovieClip;
             container_mc1.width=100;
             container_mc1.height=100;
       container_mc1.graphics.drawCircle(0,0,20);
             this.addChild(container_mc1);

you would see a circle on stage.

p.s.  s=new Shape, should be s=new Shape();

SiHoopAuthor
Inspiring
December 3, 2009

kglad,

Thanks for your reply. I modified my code as you recommended, but still no luck.Is there something else I'm missing? It works perfectly if I have the movieclip on the stage.

Here's how I changed my code:

package{
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import mvc.SlideshowModel;
    import mvc.SlideshowView;
   
    public class SlideshowDocument extends MovieClip{
        private var slideModel:SlideshowModel;
        private var slideView:SlideshowView;
        private var req:URLRequest=new URLRequest("data.xml");
        private var container_mc1:MovieClip;
        private var s:Shape;
        public function SlideshowDocument(){
            container_mc1=new MovieClip;
            container_mc1.width=100;
            container_mc1.height=100;
            container_mc1.graphics.drawCircle(0,0,200);
            slideView = new SlideshowView(container_mc);
            //slideView = new SlideshowView(container_mc1);
            this.addChild(container_mc1)
            slideModel = new SlideshowModel();
            slideView.model = slideModel;
            slideModel.load(req);
        }
    }
}

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 3, 2009

oops, you need a linestyle or fill.  in addition, you should (not) set a width/height on an empty object:


package{
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import mvc.SlideshowModel;
    import mvc.SlideshowView;
   
    public class SlideshowDocument extends MovieClip{
        private var slideModel:SlideshowModel;
        private var slideView:SlideshowView;
        private var req:URLRequest=new URLRequest("data.xml");
        private var container_mc1:MovieClip;
        private var s:Shape;
        public function SlideshowDocument(){
            container_mc1=new MovieClip;
           // container_mc1.width=100;
            //container_mc1.height=100;

container_mc1.graphics.lineStyle(1);
            container_mc1.graphics.drawCircle(0,0,200);
            slideView = new SlideshowView(container_mc);
            //slideView = new SlideshowView(container_mc1);
            this.addChild(container_mc1)
            slideModel = new SlideshowModel();
            slideView.model = slideModel;
            slideModel.load(req);
        }
    }
}