0

I am trying to pass a variable to a method in one of my Classes so I can use it to create the correct movieClip (image)

My Class code looks like this:

package  {
    import flash.display.MovieClip;
    import flash.display.Sprite;


    public class SlideShow extends MovieClip{

        public function SlideShow() 
            {

                             //does something on start

        }

          //This function should take the string and use it as the class name below.
          public function addImages(BackGround:String):void
             {
            trace(BackGround);

            var main_bg:BackGround = new BackGround();
            addChild(main_bg);
                 }
         }
    }

and when I call the method from my maintimeline it looks like this:

var shoeSlide:SlideShow = new SlideShow(); 
shoeSlide.addImages("menPant"); 

SO "menPant" is acually the name I assigned to a class of a movieclip that has some images in it.

I am getting the following error:

SlideShow.as, Line 30   1046: Type was not found or was not a compile-time constant: BackGround.

1 Answer 1

2

make sure you import getDefinitionByName at the top of your class code if flash doesn't do it for you automatically. This should work.

public function addImages(BackGround:String):void
{
    var symbol_class:Class = getDefinitionByName(BackGround);
    //EDIT: removed data type :BackGround -- this will give an error.
    var main_bg = new symbol_class();
    addChild(main_bg);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Great this is what I was looking for! +1 checked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.