Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-08-2012, 08:41 PM   #1
jmlima
Registered User
 
Join Date: Jun 2012
Posts: 23
Default Trouble with instances

Trying to summarize:

I create and display a set of 'cards' , drawn from a deck, in the stage.
The displayed objects are instances of the movieclip objects from which they are created.

I then want to get a listener so that when you click on one of these cards they are removed from the screen, and added to an array to form a new deck from which later they can be dealt.

This is where I have a problem, when I click on them, all I can add to the new deck are their instance names, which prevents me from displaying them again (using addChild) or even from removing them (using removeChild).

The question:

Is there a way I can create a new object when I click on these instances, and add that object to the new deck array, so that I can use addchild and display them later?

Any help appreciated!
jmlima is offline   Reply With Quote
Old 07-08-2012, 10:30 PM   #2
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,184
Default

As far as you call the movieclip, there shouldn't be any problems in adding, removing and again adding movieclips on the stage.
-:)lauri is offline   Reply With Quote
Old 07-09-2012, 07:46 PM   #3
jmlima
Registered User
 
Join Date: Jun 2012
Posts: 23
Default

Quote:
Originally Posted by -:)lauri View Post
As far as you call the movieclip, there shouldn't be any problems in adding, removing and again adding movieclips on the stage.
hmm... right. Let me see, this is the code I'm using to add the clicked card onto a new deck (an array basically) :

function addOpponent(event:MouseEvent):void
{
var newOpp:MovieClip = MovieClip(event.currentTarget);
deckOpponent.push(newOpp);
trace(deckOpponent);
removeChild(newOpp);

}

The result of the trace noted above is the following once 4 cards have been clicked:

[object Cards],[object Cards],[object Cards],[object Cards]


So I cannot really figure how to get these objects to display again...
jmlima is offline   Reply With Quote
Old 07-09-2012, 08:19 PM   #4
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

it would probably be some variation of this:
ActionScript Code:
var index:int = 0; var c:Cards = deckOpponent[index] as Cards; addChild(c);
[afz]snickelfitz is offline   Reply With Quote
Old 07-09-2012, 08:34 PM   #5
jmlima
Registered User
 
Join Date: Jun 2012
Posts: 23
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
it would probably be some variation of this:
ActionScript Code:
var index:int = 0; var c:Cards = deckOpponent[index] as Cards; addChild(c);
Tried that, and if does pop a card from the deck, but does not show the graphics of the movieclip, only the contour?

(movieclip have got a texture graphic)
jmlima is offline   Reply With Quote
Old 07-09-2012, 08:40 PM   #6
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

Not sure how your movieclip is composed.
Does the movieclip have multiple frames?
Maybe you're not on the correct frame.
[afz]snickelfitz is offline   Reply With Quote
Old 07-09-2012, 08:53 PM   #7
jmlima
Registered User
 
Join Date: Jun 2012
Posts: 23
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
Not sure how your movieclip is composed.
Does the movieclip have multiple frames?
Maybe you're not on the correct frame.
You're right, it's a question of frames. It is getting a 'card object' from the deck, and showing the first frame in the deck timeline, which is a blank contour.

Now the question is how to make it show the correct frame...
jmlima is offline   Reply With Quote
Old 07-09-2012, 09:22 PM   #8
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

Store the frame number in a dynamic property. (MovieClip class is dynamic)
Generic concept:
ActionScript Code:
card.frameNumber = card.currentFrame; array.push(card);

You can then access correct frame using the frameNumber property.
Generic concept:
ActionScript Code:
card.gotoAndStop(card.frameNumber);
[afz]snickelfitz is offline   Reply With Quote
Old 07-10-2012, 08:47 PM   #9
jmlima
Registered User
 
Join Date: Jun 2012
Posts: 23
Default

Thanks for the tip. It got me thinking and realizing, my issue was not so much with frames, but with labels. What I needed was a way to get the label of the cards on the screen to a new array so that I could pop the cards later, what I ended up doing was the following:

function addOpponent(event:MouseEvent):void
{
var newOpp:String;
newOpp = newCardS.currentLabel;
deckOpponent.push(newOpp);
removeChild(newCardS);

}


Quote:
Originally Posted by [afz]snickelfitz View Post
Store the frame number in a dynamic property. (MovieClip class is dynamic)
Generic concept:
ActionScript Code:
card.frameNumber = card.currentFrame; array.push(card);

You can then access correct frame using the frameNumber property.
Generic concept:
ActionScript Code:
card.gotoAndStop(card.frameNumber);
jmlima is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:35 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.