Menu.itemRenderer = new ClassFactory(Renderer);

MXML compiler automatically wraps it for you, but you have to do it yourself in 
AS.


On 7/21/10 3:28 PM, "Alexander Farber" <[email protected]> wrote:






Hello, I'm trying this code, but get the error about bad casting in Test.mxml:

Implicit coercion of a value of type Class to an unrelated type
mx.core:IFactory.

My Renderer.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml";>
<mx:Text text="{data.label}" fontSize="16" fontWeight="bold"/>
</mx:HBox>

My Test.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; creationPolicy="all">
<mx:Style>
@font-face {
src:url("C:\\WINDOWS\\Fonts\\times.ttf");
fontFamily: myFont;
/* card suits */
unicodeRange: U+2660-U+266B;
}
Menu {
fontFamily: myFont;
fontSize: 24;
}
</mx:Style>

<mx:Script>
<![CDATA[
import mx.controls.*;

private function createMenu():void {
var bids:Array = [{label: "Pass"}];
for (var i:uint = 7; i <= 10; i++)
for (var j:uint = 0; j < 4; j++)
 // string with 4 card
suits below:
bids.unshift({label: i+"♠♣♦♥".charAt(j%4)});

var menu:Menu = new Menu();
menu.dataProvider = bids;
 // XXX the line below fails:
menu.itemRenderer = Renderer;
menu.selectedIndex = 0;
pub.popUp = menu;
}

]]>
</mx:Script>

<mx:Canvas width="100%" height="100%">
</mx:Canvas>

<mx:ApplicationControlBar width="100%">
<mx:Spacer width="100%"/>
<mx:PopUpButton id="pub" creationComplete="createMenu();"/>
</mx:ApplicationControlBar>
</mx:Application>

I've tried adding itemRenderer="Renderer" to the PopUpButton tag,
but it isn't accepted (I guess the renderer belongs to the Menu)

Regards
Alex





--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui

Reply via email to