• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

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!

TOPICS
ActionScript

Views

2.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jun 15, 2012 Jun 15, 2012

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;

}

Votes

Translate

Translate
Enthusiast ,
Jun 12, 2012 Jun 12, 2012

Copy link to clipboard

Copied

Hi,

Can you paste your code here.

Regards,

Kartik.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 12, 2012 Jun 12, 2012

Copy link to clipboard

Copied

import flash.display.MovieClip;

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

        // accessing the mc from libray here qmc is linkage name

        myMovieClip = new qmc();

        myMovieClip.x=stage.stageWidth/10;

        myMovieClip.y=stage.stageHeight/3;

        addChild(myMovieClip);

   }

i think all 12 mc are loading in same place, i want to display the mc one by one

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2012 Jun 12, 2012

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 12, 2012 Jun 12, 2012

Copy link to clipboard

Copied

Sorry am not finding any difference it is showing the same output

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2012 Jun 12, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 12, 2012 Jun 12, 2012

Copy link to clipboard

Copied

hi i got the solution for my problem. it is worlking fine.

But i got another problem i don't know how to control the each mc.I want to perform different action with those mc.

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;

// here is the problem

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 13, 2012 Jun 13, 2012

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 14, 2012 Jun 14, 2012

Copy link to clipboard

Copied

Hi,

This program is not working, when i trace e.currentTarget.name am getting the output as mc, can you please give me another solution.I think problem with for loop

Because when i press any of the mc the out put is coming as mc4

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 14, 2012 Jun 14, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 14, 2012 Jun 14, 2012

Copy link to clipboard

Copied

Sorry it is not working

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 14, 2012 Jun 14, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 15, 2012 Jun 15, 2012

Copy link to clipboard

Copied

mc is instance of name one button it is there inside the myMovieClip.

For the my myMovieClip when i gave the different name like this myMovieClip.name = "mc"+i

am getting the myMovieClip name as mc1 ,mc2,mc3,mc4

I want to perform one action when i press mc1.mc the myMovieClip.atext should be visible true like wise for mc2..

But it is not happening

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 15, 2012 Jun 15, 2012

Copy link to clipboard

Copied

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 15, 2012 Jun 15, 2012

Copy link to clipboard

Copied

Thanks Its working fine

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 15, 2012 Jun 15, 2012

Copy link to clipboard

Copied

LATEST

You are welcome.

Please mark at the answer as Correct Answer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines