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

How can I display a Movie clip from library on stage in AS3?

New Here ,
Mar 11, 2010 Mar 11, 2010

Hi,

I have a movie clip in my library and I would like to display it on the stage using AS3.

do I have to define it as a variable?Do  I need to use this code:  addchild(movieclip);

can I use the 'x' and 'y' to position it?

What would the code look like?

Ben.

TOPICS
ActionScript
1.3K
Translate
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

Explorer , Mar 11, 2010 Mar 11, 2010

Steps:

  1. Right-click Moviclip from library and choose: Linkage...
  2. Select the checkbox to Export for ActionScript.
  3. Give the class "mov_clip"
var movie:mov_clip = new mov_clip;
movie.x = 50;
movie.y = 50;
addChild:(movie);
Translate
Explorer ,
Mar 11, 2010 Mar 11, 2010

Steps:

  1. Right-click Moviclip from library and choose: Linkage...
  2. Select the checkbox to Export for ActionScript.
  3. Give the class "mov_clip"
var movie:mov_clip = new mov_clip;
movie.x = 50;
movie.y = 50;
addChild:(movie);
Translate
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
Advocate ,
Mar 11, 2010 Mar 11, 2010

Typo: no colon in addChild

Translate
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
New Here ,
Mar 11, 2010 Mar 11, 2010

Great! it works  well ! thanks

But I have another question, if I wanted to used the same movie clip but postion it at different x and y positions when a different btn is selected how could I do that?

Would I have to make a copy of the movie clip and give it a different name?

or is there an better way around it?

Ben.

Translate
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
Advocate ,
Mar 11, 2010 Mar 11, 2010

While the movieclip is added to the stage with addChild, you can move it around by assigning it's x and y properties anytime you like. So on a button press, just position it wherever you like.

Translate
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
New Here ,
Mar 11, 2010 Mar 11, 2010

Ok..

But I guess the problem I have is that I want this one moive clip to be in two different places at the same time! I have two different buttons but I want to display the same movie clip when both buttons are pressed independently so the move clip will have to be at two different locations!

Translate
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
Advocate ,
Mar 11, 2010 Mar 11, 2010

Why not create two instances of that movie clip class?

var mc1:YourMcInLibrary = new YourMcInLibrary();

var mc2:YourMcInLibrary = new YourMcInLibrary();

mc1.x = 50;

mc1.y = 50;

mc2.x = 150;

mc2.y = 150;

addChild(mc1);

addChild(mc2);

Translate
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
New Here ,
Mar 11, 2010 Mar 11, 2010

Perfect !! you are a legend!!

thanks very much Harry.

Cheers,

Ben.

Translate
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
Explorer ,
Mar 11, 2010 Mar 11, 2010

I hope the follwing basic method will work.

var movie:box=new box();
var movie1:box=new box();
butn.addEventListener(MouseEvent.CLICK,btnpressed);

function btnpressed(etc:MouseEvent):void{
movie.x=50;
movie.y=100;
movie1.x=200;
movie1.y=100;
addChild(movie);
addChild(movie1);
}

Translate
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
New Here ,
Mar 11, 2010 Mar 11, 2010
LATEST

Fantastic! Thank you.

Translate
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
Advocate ,
Mar 11, 2010 Mar 11, 2010

You're welcome!

Translate
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
New Here ,
Mar 11, 2010 Mar 11, 2010

Thanks Spvr, works well thanks.

I had another question which I repied to the wrong person!! would you mind having a look at my last post?

Cheers,

Ben.

Translate
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