Call the parent function from itemRenderer

I want to call a parent function called "edit_groups ()" from itemRenderer. Code for my itemRenderer:

<mx:VBox id="vbx_container" paddingBottom="4" paddingLeft="4" paddingRight="4" paddingTop="4" borderStyle="solid" dropShadowEnabled="true" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Canvas width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Image id="image" width="100" height="100" source="{data.thumb}" scaleContent="true" maintainAspectRatio="true" complete="{image_smoothing_handler(event);}" trustContent="true" doubleClick="{CALL THE PARENT FUNCTION "edit_groups()"}"/> </mx:Canvas> </mx:VBox> 

And I call my itemRenderer from an application like:

 list_groups_modify.itemRenderer=new ClassFactory(groups.list_groups_modify_item_renderer); <mx:Label text="{data.label}" textAlign="center" maxWidth="60" toolTip="{data.label}"/> 

Relations Zeeshan

+4
source share
7 answers

Try this using parentDocument :

 <mx:VBox id="vbx_container" paddingBottom="4" paddingLeft="4" paddingRight="4" paddingTop="4" borderStyle="solid" dropShadowEnabled="true" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Canvas width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Image id="image" width="100" height="100" source="{data.thumb}" scaleContent="true" maintainAspectRatio="true" complete="{image_smoothing_handler(event);}" trustContent="true" doubleClick="parentDocument.edit_groups()"/> </mx:Canvas> </mx:VBox> 
+6
source

You can reference outerDocument as follows

 <mx:VBox id="vbx_container" paddingBottom="4" paddingLeft="4" paddingRight="4" paddingTop="4" borderStyle="solid" dropShadowEnabled="true" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Canvas width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Image id="image" width="100" height="100" source="{data.thumb}" scaleContent="true" maintainAspectRatio="true" complete="{image_smoothing_handler(event);}" trustContent="true" doubleClick="{outerDocument.edit_groups()}"/> </mx:Canvas> </mx:VBox> 
+2
source

Make sure you are trying to set a link to a public function or variable.

+2
source

If you get error 1069 and the item renderer is a separate mxml component , you may need to use:

 parentDocument.parentDocument.functionName(); 
0
source

I also came across similar situations, but, in my opinion, the best way is to send some kind of custom event from the element renderer and catch this event inside the parent component. Inside the eventlistener, the parent function is called. This will work even if itemrenderer is in a separate mxml or actionscript file.

0
source

I stumbled upon this post, having encountered a similar problem after upgrading to Flex SDK 4.6. I was getting terrible error 1069 with code that worked fine. The preferred answer did not work.

However, I solved this by changing it to use:

 document.owner.parentDocument 
0
source

You can also use this piece of code (placed in the item renderer) to find the following applicable parent:

 internal function findTarget():MyTargetClass { for (var p:* = this; !(p is MyTargetClass || p == null); p = p.parentDocument) {} return p; } 

Usage example:

 override public function set data(value:Object):void { super.data = value; findTarget().myFunction(value); } 
0
source

Source: https://habr.com/ru/post/1300491/


All Articles