ForumsProgramming Forumhow do i place an item from my libary to the game

6 3091
GuardianGames
offline
GuardianGames
25 posts
Nomad

How would i place an item, lets call it "ITEM", from my library to the game at x=40 y=50?

  • 6 Replies
No_Thumbs
offline
No_Thumbs
20 posts
Nomad

set the class name to ITEM

var item:MovieClip = new ITEM();
item.x = 40;
item.y = 50;
addChild(item);

LonLonRanch
offline
LonLonRanch
172 posts
Nomad

You also have to make sure that when you create the movieClip, you select the "export from Actionscript" tab - it's under the 'advanced' tab when you're creating a movieClip. You can also right click the movieClip you wish to add from your library and click on 'roperties' - that will give you the same menu. Also No_Thumbs' code above is for Actionscript 3.0, if you're still coding with actionscript 2.0 it will be a little different.

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Right click on your item on your library and select Linkage, mark "Export for ActionScript" and give it an Identifier, it works pretty much like a instance name but for library

Then you can use attachMovie, like this

YourItemName = attachMovie("YourItemIdentifier", "TheNameofthisNewInstanceofYourItem", the depth of your item, { _x:YourX , _y:YourY });


You can't have two movie clips on the same depth or they won't work, you can solve that by using _root.getNextHighestDepth()

For the new name you can either use a variable or use the same number as the depth on the name, thus making each of them different, "TheNameofthisNewInstanceofYourItem"+_root.getNextHighestDepth()
GuardianGames
offline
GuardianGames
25 posts
Nomad

thax

PixelSmash
offline
PixelSmash
566 posts
Nomad

Do note that both AS2 and AS3 were quoted in this thread... using both, no matter which version of Flash you're using, will generate quite a few errors...

clipmaster3
offline
clipmaster3
104 posts
Nomad

set the class name to ITEM

var item:MovieClip = new ITEM();
item.x = 40;
item.y = 50;
addChild(item);


the second line should be
var item:ITEM = new ITEM();
Showing 1-6 of 6