07-08-2012, 08:41 PM
|
#1
|
|
Registered User
Join Date: Jun 2012
Posts: 22
|
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!
|
|
|
07-08-2012, 10:30 PM
|
#2
|
|
Senior Member
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,161
|
As far as you call the movieclip, there shouldn't be any problems in adding, removing and again adding movieclips on the stage.
|
|
|
07-09-2012, 07:46 PM
|
#3
|
|
Registered User
Join Date: Jun 2012
Posts: 22
|
Quote:
Originally Posted by -:)lauri
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...
|
|
|
07-09-2012, 08:19 PM
|
#4
|
|
Senior Member
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,898
|
it would probably be some variation of this:
ActionScript Code:
var index:int = 0;
var c:Cards = deckOpponent[index] as Cards;
addChild(c);
|
|
|
07-09-2012, 08:34 PM
|
#5
|
|
Registered User
Join Date: Jun 2012
Posts: 22
|
Quote:
Originally Posted by [afz]snickelfitz
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)
|
|
|
07-09-2012, 08:40 PM
|
#6
|
|
Senior Member
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,898
|
Not sure how your movieclip is composed.
Does the movieclip have multiple frames?
Maybe you're not on the correct frame.
|
|
|
07-09-2012, 08:53 PM
|
#7
|
|
Registered User
Join Date: Jun 2012
Posts: 22
|
Quote:
Originally Posted by [afz]snickelfitz
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...
|
|
|
07-09-2012, 09:22 PM
|
#8
|
|
Senior Member
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,898
|
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);
|
|
|
07-10-2012, 08:47 PM
|
#9
|
|
Registered User
Join Date: Jun 2012
Posts: 22
|
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
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);
|
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 06:30 PM.
///
|
|