开发者

how to access flex component id's generically?

开发者 https://www.devze.com 2023-01-07 09:42 出处:网络
I have some generic functions like copy, paste,etc in an AS file. I want to use them for editing data present in different mxml applications embedded in one application. If I pass the child\'s compone

I have some generic functions like copy, paste,etc in an AS file. I want to use them for editing data present in different mxml applications embedded in one application. If I pass the child's component id as a parameter of a function in one of the events, I get the value as either null or the parent app name. But I want the id of the child's component to access the values. Please help.

Update:

Please find the code snippets below:

epfGateTask.mxml

..
<mx:AdvancedDataGrid id="task" resizableColumns="true" initialize="populateArray()"
 dataProvider="{gateTaskList}" width="100%" height="100%" horizontalScrollPolicy="auto" 
verticalScrollPolicy="auto" selectionMode="multipleCells" editable="true" itemEditBeginning="{editStart(event,task)}" paddingTop="开发者_高级运维0" paddingBottom="0" lockedColumnCount="5" rowCount="27"  sortableColumns="false" liveScrolling="false" variableRowHeight="true" headerWordWrap="true" >
<mx:columns>
<mx:AdvancedDataGridColumn id="gateName" dataField="gateName" headerText="" width="137" wordWrap="true" textAlign="center" editable="false"/>
...

MenuBarUtilities.as

...
var dg_ID :Object ; 

public function cut(event: Event)
{

    if(selectedData != null && selectedData!="")
    {
        copy(event);
        dg_ID.selectedItem[columnName]= "";
        dg_ID.invalidateList();
    }
}

public function editStart(event:AdvancedDataGridEvent,id:Object):void
{   
    dg_ID = id;
    columnIndex  = event.columnIndex;
    columnName = id.columns[columnIndex].dataField;
    var dataField: String = id.selectedItem[columnName];
    selectedData = dataField;       
}
...

This function is to save the value of the datafield in a temporary variable, so that on copy and paste the value can be pasted. Here, 'id' as you can see from above, is(dataGrid id) what is being passed from the AdvancedDataGridEvent. Now on executing the main mxml and selecting a datagrid cell to cut the value, null reference error is shown. the id in the function has a value as "epfProgram", which is the main mxml name. And dg_ID is shown as null. Similarly the same functionality is required from another mxml. Both these mxml are put in a main mxml(epfProgram.mxml), using SWFLoader. And the copy, paste, etc buttons are present in the main mxml. Please help me in fixing this issue.


Without seeing any code, I'd recommend sending a reference to the component in your event rather than sending the id. Actually, now that I say that you could probably just skip that altogether and access the sending component via the currentTarget property of the event that you receive in your event listener.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号