During daily flex development, we often encounter various types of XML and Icon embedding. How to conveniently and quickly manage these files becomes the key point to improve development efficiency.
I recently encountered some trouble when I made a right-click menu in flex. I will summarize my recent experience here and I will forget it.
First, it is embedded in XML (here, mimetype can only be specified as binary)
[Embed (Source = "/assets/XML/contextmenu. XML ", mimetype =" application/octet-stream ")] private var menuconfig: Class; // read var Bytes: bytearray = new menuconfig; var menuconfig: xml = New XML (bytes. readutfbytes (bytes. length ));
Another method is to add it to mxml and then reference it by ID.
<fx:XML id="menuConfig" source="/assets/xml/contextmenu.xml"/>
Below is the icon embedding
Write the icons to be embedded in an as file, and then load the as file in the main application.
Icons. As (Note: The scope must be public and static. Do not add package and class declarations. An error will be reported during compilation)
[Embed("/assets/images/arcgis16/add.png")]public var AddIcon:Class;[Embed("/assets/images/arcgis16/FolderBlueAdd.png")]public var AddGroupIcon:Class;[Embed("/assets/images/arcgis16/addressAdd.png")]public var AddAddressIcon:Class;[Embed("/assets/images/arcgis16/sketch.png")]public var SketchIcon:Class;[Embed("/assets/images/arcgis16/properties.png")]public var PropertiesIcon:Class;[Embed("/assets/images/arcgis16/delete.png")]public var DeleteIcon:Class;
And then introduce
<fx:Script source="/assets/script/Icons.as"/>
This method is suitable for data source configuration of controls such as menu and menubar, because their data sources are usually XML and the icon attribute can be configured, which is quite convenient.
VaR rightclickmenu: menu = menu. createmenu (flexglobals. toplevelapplication as displayobjectcontainer, menuconfig, false); rightclickmenu. labelfield = "@ label"; // iconfield must be specified; otherwise, the icon does not take effect in rightclickmenu. iconfield = "@ icon"; // arrange menus closely in rightclickmenu. variablerowheight = true; rightclickmenu. addeventlistener (menuevent. item_click, Handler );
Flex embed XML and icon