If your item classes are card1, card2, card3 and so on, and your code currently works...
AboutButton.addEventListener(MouseEvent.CLICK, gocard); function gocard(e:MouseEvent):void { /// var cardName:String = "card"+String(1 + uint(Math.random()*49)); // 49 is the number of clips you have var cardClass:Object = getDefinitionByName(cardName) as Object var newcard:* = new cardClass(); // replace the asterisk i used for the base class that all your cards extend from /// this.addChild(newcard); newcard.x = 25; newcard.y = 45; } i haven't really tested this code so you might need to fiddle with it. 2008/6/30 Bassam M <[EMAIL PROTECTED]>: > Dear Ashim > > I didn't understanad hot to do it can you do sample for me with button on > click on the button will insert the card to the stage > > I tryed to do it my self I user this code to insert the card from stage but > I couldn't use with your code > > this is my code to insert card1 i don't know how to make it random > > AboutButton.addEventListener(MouseEvent.CLICK, gocard); > function gocard(e:MouseEvent):void { > var newcard:card1 = new card1(); > this.addChild(newcard); > newcard.x = 25; > newcard.y = 45; > } > > thank you > > On 6/30/08, Ashim D'Silva <[EMAIL PROTECTED]> wrote: >> >> If you're using AS3, everything in your library that's set to export >> for Actionscript will have a unique Class which you need to call to >> instantiate it. >> Use getDefinitionByName to turn a randomly selected string into a >> class definitiion and then call it. >> >> Example: >> >> If your library has 50 objects and their named: Card1, Card2, Card3 and so >> on. >> >> var cardName:String = "Card"+String(1 + uint(Math.random()*49)); >> var cardClass:Object = getDefinitionByName(cardName) as Object >> var card:Sprite = new cardClass(); >> >> The last line you can substitue your classes and parameters. Then run >> this code 7 times. >> >> 2008/6/30 Bassam M <[EMAIL PROTECTED]>: >> > Hi >> > >> > I'm trying to make game in this game I have 50 movie clip in the library >> > I want when I click on one button call draw i want to show 7 of this >> movie >> > clips on the stage but i want to select randomly 7 of 50 or more or once >> i >> > click draw i want to draw one card by one random >> > can anyone help me please how to do it >> > >> > Tank you >> > Bassam >> > _______________________________________________ >> > Flashcoders mailing list >> > Flashcoders@chattyfig.figleaf.com >> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > >> >> >> >> -- >> Random Lines 3D >> My online portfolio >> www.therandomlines.com >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- Random Lines 3D My online portfolio www.therandomlines.com _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders