The compiler says:
"**Error** Deck.as: There is no method with the name 'setDepthTo'.
this.setDepthTo(DepthManager.kTop);"
And from your code I don't see it either: this.setDepthTo or
this.filters. When you say "it works"
do you mean it compiles ok or that onPress the card acts the way it
should visually? Took a quick look at UIComponent and didn't see them
there either.. I wouldn't be surprised if you traced those two
calls and they would be undefined.
Hope this helps,
Rob.
Alexander Farber wrote:
Hello,
I'm trying to create a v2 component representing a deck
of playing cards and I have a problem, which I believe is
very common, but I can't find a solution on the net yet.
My code is simple and is listed completely at the bottom.
And the problem is, that when I assign an event handler to
each (child) card MC in my cards_array this way (is it called
"closure"?) in the Deck.createChildren(), then it works ok:
card.onPress = function() {
this.setDepthTo(DepthManager.kTop);
this.filters = _parent.shadow_array;
}
But when I try to move the code above into a separate
method of the parent Deck class like this:
card.onPress = raiseCard;
or even:
card.onPress = Delegate.create(card, raiseCard);
Then the compiler will complain - even though I believe the
scope (the card) is correct - and the Deck.as won't compile:
**Error** Deck.as: There is no method with the name 'setDepthTo'.
this.setDepthTo(DepthManager.kTop);
What is the workaround here? Thank you
Regards
Alex
class Deck extends UIComponent
{
static var symbolName:String = 'Deck';
static var symbolOwner:Object = Deck;
var className:String = 'Deck';
private var bb_mc:MovieClip;
private var cards_array:Array;
var shadow_array:Array;
function Deck() {
}
private function init():Void {
super.init();
bb_mc.unloadMovie();
shadow_array = [ new DropShadowFilter(0, 90, 0x000000,
0.30, 10, 10, 1, 1, false, false, false) ];
cards_array = [];
}
private function createChildren():Void {
for (var i:Number = 0; i <= 32; i++) {
var card_name:String = 'card_' + (i + 1) + '_mc';
var card:MovieClip = cards_array[i] =
this.createChildAtDepth(i, DepthManager.kTop);
// card.onPress = raiseCard;
// card.onPress = Delegate.create(card, raiseCard);
card.onPress = function() {
trace('CLICKED CARD: ' + _width + ' x ' + _height +
' @ ' + _x + ', ' + _y + ' ' + _rotation);
this.setDepthTo(DepthManager.kTop);
this.filters = _parent.shadow_array;
}
}
size();
}
function raiseCard():Void {
trace('CLICKED CARD: ' + _width + ' x ' + _height +
' @ ' + _x + ', ' + _y + ' ' + _rotation);
this.setDepthTo(DepthManager.kTop); // XXX PROBLEM
this.filters = _parent.shadow_array;
}
private function size():Void {
super.size();
//if (! (this.__width > 0 && this.__height > 0)
//return;
for (var i:Number = 0; i <= 32; i++) {
var card:MovieClip = cards_array[i];
card._x = Math.floor(Math.random() * (this.__width -
card._width));
card._y = Math.floor(Math.random() * (this.__height -
card._height));
card._rotation = Math.floor(Math.random() * 10 - 5);
}
invalidate();
}
private function draw():Void {
super.draw();
}
}
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com