Flex embed XML and icon

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.