Skip navigation
Currently Being Moderated

adding mc from libray to the stage by using one linkage name

Jun 11, 2012 11:57 PM

hi,

 

I was just about to ask this question, glad this has been answered. However, in my project I need to add multiple instance of the class from library dynamically, I know how to do it in AS2 way, can anyone elighten me with AS3 way, specifically with this new addchild(movieclip) function?

 

 

thanks!

 
Replies
  • Currently Being Moderated
    Jun 12, 2012 12:14 AM   in reply to lalitha subramanian

    Hi,

     

    Can you paste your code here.

     

    Regards,

    Kartik.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 12, 2012 12:26 AM   in reply to lalitha subramanian

    You can use it in following way :-

     

    for (var i:int=0; i<12; i++) {

            var myMovieClip:qmc = new qmc();// accessing the mc from libray here qmc is linkage name

            myMovieClip.x=stage.stageWidth/10;//assigning x property

            myMovieClip.y=stage.stageHeight/3;//assigning y property

            addChild(myMovieClip);//adding to stage

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 12, 2012 12:46 AM   in reply to lalitha subramanian

    What kind of output you want?

     

    As i have seen your code you are doing it correct apart from the line 1 in for loop which i have corrected.

     

    Regards,

    Kartik.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 13, 2012 8:14 AM   in reply to lalitha subramanian

    Hello,

     

    Please try the below mentioned code :-

     

    for (var i:int=1; i<(len+1); i++) {

        

             myMovieClip = new qmc();

     

            if (i==1) {

     

                var yval:int=stage.stageHeight/3;

             

            } else {

     

                yval=yval+myMovieClip.height+5;

     

            }

            myMovieClip.x=stage.stageWidth/10;

            myMovieClip.y=yval+10;

            addChild(myMovieClip);

     

            myMovieClip.qtext.text=i+". "+ques_arr[i-1];

            myMovieClip.atext.autoSize="center"

            myMovieClip.atext.text=ans_arr[i-1];

            myMovieClip.atext.visible=false;

     

                        myMovieClip.name = "mc"+i // adding name to movieclip

     

    // here is the problem

            myMovieClip.mc.addEventListener(MouseEvent.MOUSE_DOWN,showans);

    }

     

     

    function showans(e:MouseEvent):void

    {

              trace(e.currentTarget.name)//here you will get the name of movieclip you have defined above here you can put a condition check. output will be like "mc1" "mc2" ...

              //here you can write your code to handle different movieclip events

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 14, 2012 8:17 AM   in reply to lalitha subramanian

    Can you please change this line  myMovieClip.mc.addEventListener(MouseEvent.MOUSE_DOWN,showans); to  myMovieClip.addEventListener(MouseEvent.MOUSE_DOWN,showans); and try again.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 14, 2012 9:16 PM   in reply to lalitha subramanian

    Please explain the problem clearly.  I have some doubts, What do you mean by mc? Whether it is myMovieClip or something else. And different action means for each mc you want to create a seperate action right?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 15, 2012 2:08 AM   in reply to lalitha subramanian

    First check whether you gave the instance name for the button as "mc" in your myMovieClip.

     

    Then write your code same

    myMovieClip.mc.addEventListener(MouseEvent.MOUSE_DOWN,showans);  // You can write CLICK event also...

     

    In showans, You have to write like this.

     

    function showans(e:MouseEvent):void

    {

         e.currentTarget.parent.atext.visible = true;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 15, 2012 4:45 AM   in reply to lalitha subramanian

    You are welcome.

     

    Please mark at the answer as Correct Answer.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points