So the short answer is: No, you can't add your sprite to the 1st Canvas.
Long answer: One of the most important base classes within Flex is
Container (the parent of Canvas). In container's addChild()
documentation there's this gem:
"Note: While the child argument to the method is specified as of type
DisplayObject, the argument must implement the IUIComponent interface
to be added as a child of a container. All Flex components implement
this interface."
So basically there is a wall: On one side of it there are Flex
components, on the other side there are Flash display primitives. This
is a feature, not a bug. :)
You have two (similar) options:
The first is to create a Deck 'wrapper' UIComponent that contains your
deck. This will allow you to re-use your deck in pure ActionScript
projects if needed in the future.
The other is to make Deck extend UIComponent instead of Sprite. This
requires a little less code, and may look cleaner, depending.
Here is an example for a 'wrapper' :
package
{
import mx.core.*;
public class DeckComponent extends UIComponent
{
[Bindable]
public var label:String;
private var deck:Deck;
public function DeckComponent()
{
super()
}
protected override function createChildren():void
{
super.createChildren();
deck = new Deck();
//add your event listeners here....
addChild(deck);
}
protected override function
updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
deck.resize(unscaledWidth, unscaledHeight); //perhaps
you'll want
to change the size of the deck?
}
}
}
And then you can do this:
<mx:TabNavigator width="100%" height="100%">
<myPackage:DeckComponent label="Playing table"
width="100%" height="100%" />
<mx:Canvas label="Score" width="100%" height="100%">
</mx:Canvas>
or:
<mx:TabNavigator width="100%" height="100%">
<mx:Canvas label="Playing table" width="100%" height="100%">
<myPackage:DeckComponent width="100%" height="100%" />
</mx:Canvas>
<mx:Canvas label="Score" width="100%" height="100%">
</mx:Canvas>
Peace
C
On Sat, Mar 20, 2010 at 3:24 PM, Alexander Farber
<[email protected]> wrote:
> Thank you for the explanations and -
>
> On Sat, Mar 20, 2010 at 7:04 PM, Chris <[email protected]> wrote:
>> http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_2.html
>
> I've started to read it. But maybe someone can give me a start:
>
> If I have a Canvas in Flex:
>
> <mx:TabNavigator width="100%" height="100%">
> <mx:Canvas label="Playing table" width="100%" height="100%">
> </mx:Canvas>
> <mx:Canvas label="Score" width="100%" height="100%">
> </mx:Canvas>
> ....
>
> can't I just somehow add my Sprite to the 1st Canvas above?
>
> In Flash I'd just:
>
> _deck = new Deck();
> _deck.addEventListener(CardEvent.CLICKED, handleCardClicked);
> _deck.addEventListener(CardEvent.PLAYED, handleCardPlayed);
> addChild(_deck);
>
> Regards
> Alex
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders