You cant use mxml which takes care of the typing niceties.
the problem is that you cant do this:
myMenu= Menu.createMenu(parent, menuData, false);
myMenu.itemRenderer=ThumbPopUpRenderer;
Where ThumbPopUpRenderer is an MXML component. It gives you a type error because itemRenderer is of type IFactory and ThumbPopupRenderer is not.
But if you do this:
myMenu= Menu.createMenu(parent, menuData, false);
myMenu.itemRenderer=ThumbPopUpRenderer as IFactory;
It runs, but apparently an MXML itemRenderer is not of the right type, so it throws a runtime error.
Any ideas?
Hank
lol.
Just five minutes ago I switched to an array and got it working.
It looks like you cant create a field of type class in an xml object, or at least I wasnt able to. It seems to want to interpret it as text. When putting braces around it it doesnt work either.
But you are right. It was the wrong strategy anyway because the icon is left justified, so it looks wierd. I am just (today) playing with itemRenderers so I will give that a shot. In fact this popup is being used inside an itemrenderer that is inside a datagrid! So it looks like I will just have to do the next level :)
Thanks for taking a look. It was driving me crazy.
HankOn 7/16/06, Tim Hoff <[EMAIL PROTECTED]> wrote:Hi Hank,
I couldn't get this to work with xml. So, I changed the dataProvider to an array and used an iconFunction. It works, but if you select an icon, when the menu is displayed a second time the icon is also used as the selected icon. For what you are trying to do, I would recommend that you use an itemRenderer for your menu items. That way you can still use xml and control the positioning of the icon image. I know that you have asked this question a couple of time, so I thought I would give it a try. I can see why you are having problems with this.
-TH
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml"creationComplete="initList();">
<mx:Script>
<![CDATA[
import mx.controls.Menu ;
import mx.events.MenuEvent;
import mx.controls.Alert;
import flash.geom.Point;[Embed(source='../assets/assets.swf', symbol='thumbsdown')]
public var thumbsup:Class;
[Embed(source='../assets/assets.swf', symbol='thumbsup')]
public var thumbsdown:Class;// Define data provider.
private var myDP: Array;
private function initList():void {
myDP = [
{label:'No Vote', icon:''},
{label:'', icon:'thumbsup'},
{label:'', icon:'thumbsdown'}];
}
private var point1:Point = new Point();
private var myMenu:Menu;
// Create and display the Menu control.
private function showMenu():void {myMenu=Menu.createMenu(parent, myDP, false);
myMenu.labelField="label";
myMenu.iconFunction=myIconfunction;
myMenu.addEventListener("itemClick", menuHandler);
// Calculate position of Menu in Application's coordinates.
point1.x=linkButton.x ;
point1.y=linkButton.y;
point1= linkButton.localToGlobal(point1);
myMenu.show(point1.x, point1.y + linkButton.height + 1);
}
// Event handler for the Menu control's change event.
private function menuHandler(event:MenuEvent):void {
Alert.show("Label: " + event.item.label, "Clicked menu item");
}
// Determine icon based on icon field.
private function myIconfunction(item:Object):Class
{
if (item.icon == "thumbsup") {
return thumbsup;
}
if (item.icon == "thumbsdown") {
return thumbsdown;
}
return null;
}
]]>
</mx:Script><mx:LinkButton id="linkButton" width="100"
icon="@Embed(source='../assets/assets.swf', symbol='thumbsup')"
click="showMenu();"/>
</mx:Canvas>
--- In flexcoders@yahoogroups.com , "hank williams" <[EMAIL PROTECTED]> wrote:
>
> I am trying to get a menu to display some icons, and I cant get them to show
> up. The code I have written is based on the sample code for creating a popup
> menu and the sample code for creating a list where they show you how to
> include an icon. But the two examples are different enough that I may not be
> merging them together right.
>
> The other thing that is odd is, if you look at the code you will se a line
> that looks like this:
> myMenu.labelField="@label"
>
> I dont know why I need the @ here at all. But without it the label doesnt
> show up whereas with it it does. But for the following line
> myMenu.labelField= "@icon"
>
> The icons dont show up.
>
> I know that I am embedding the icon properly because the code also embeds
> one of the same icons inside the button.
>
> Any help appreciated.
>
> Hank
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" >
>
> <mx:LinkButton id="linkButton" width="100"
> icon="@Embed(source='../assets/assets.swf', symbol='thumbsup')"
> click="showMenu();">
>
> <mx:Script>
> <![CDATA[
>
> import mx.controls.Menu;
> import mx.events.MenuEvent;
> import mx.controls.Alert;
> import flash.geom.Point;
>
> [Embed(source='../assets/assets.swf', symbol='thumbsup')]
> public var thumbsup:Class;
> [Embed(source='../assets/assets.swf', symbol='thumbsdown')]
> public var thumbsdown:Class;
>
> private var point1:Point = new Point();
> private var myMenu:Menu;
>
> // Create and display the Menu control.
> private function showMenu():void {
> myMenu= Menu.createMenu(parent, myMenuData, false);
> myMenu.labelField="@label"
> myMenu.iconField= "@icon"
> myMenu.addEventListener("itemClick", menuHandler);
>
> // Calculate position of Menu in Application's
> coordinates.
> point1.x=linkButton.x;
> point1.y=linkButton.y ;
> point1=linkButton.localToGlobal(point1);
>
> myMenu.show(point1.x, point1.y + linkButton.height + 1);
> }
>
> // Event handler for the Menu control's change event.
> private function menuHandler(event:MenuEvent):void {
> Alert.show("Label: " + event.item.label, "Clicked menu
> item");
> }
> ]]>
> </mx:Script>
> </mx:LinkButton>
> <mx:XML id="myMenuData">
> <root>
> <menuitem label="No vote"/>
> <menuitem icon="thumbsup"/>
> <menuitem icon="thumbsdown"/>
> </root>
> </mx:XML>
>
> </mx:Canvas>
>
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Web site design development | Computer software development | Software design and development |
Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.