We help IT Professionals succeed at work.

access data from one component to other component in actionscript

royjayd
royjayd asked
on
hi guys

I have two components.

TextareaComponent
DatagridComponent

public class TextareaComponent extends FormItem{
public function TextareaComponent()  {
super();
grid = new DatagridComponent(); 
this.textArea.addEventListener(flash.events.KeyboardEvent.KEY_UP,callPopulate);
}

private function callPopulate(event: flash.events.KeyboardEvent) : void {
if(grid != null && grid.lookupdataForFilter != null){
var lookupdata:ArrayCollection =  grid.lookupdataForFilter; //data from DatagridComponent 
	}	
}

Open in new window



public class DatagridComponent extends VBox  
{
[Bindable] public var lookupdataForFilter:ArrayCollection = new ArrayCollection();
public function DatagridComponent()
{
super();
Swiz.dispatchEvent(new GlobalScreenEvent(GlobalScreenEvent.POPULATE_LOOKUP));
}

[Mediate(event="GlobalScreenEvent.LOOKUP_RECEIVED", properties="data")]
public function populateLookUp( data:Object ):void{
lookupdataForFilter = data as ArrayCollection;  //contains the data
	}
} 
}

Open in new window


TextareaComponent   is rendered first
DatagridComponent  is rendered second.


My goal is to access lookupdataForFilter defined in the DatagridComponent  from my TextareaComponent
I have defined lookupdataForFilter  as bindable  
I put a breakpoint on this line >>lookupdataForFilter = data as ArrayCollection;  and i see the data.

but when KEY_UP event is invoked from  TextareaComponent  'grid.lookupdataForFilter' is empty.

any idea where i am going wrong?

thanks
 
Comment
Watch Question

Top Expert 2011

Commented:
Are you sure you are setting data before executing key up event?

Do next:

public function populateLookUp( data:Object ):void{
     lookupdataForFilter = data as ArrayCollection;  //contains the data
    trace("TRACE 1: " + lookupdataForFilter);
}

private function callPopulate(event: flash.events.KeyboardEvent) : void {
   trace("TRACE 2: " + (grid ? grid.lookupdataForFilter : "NULL"));
   if(grid != null){
       var lookupdata:ArrayCollection =  grid.lookupdataForFilter; //data from DatagridComponent

Author

Commented:
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

TRACE 2:

The data is not being set but i am not sure where its missing  since i am making the  lookupdataForFilter  as Bindable
Top Expert 2011

Commented:
Did you get in this order TRACE 1 then TRACE 2?
Top Expert 2011

Commented:
public function DatagridComponent()
{
super();
trace("TRACE 0");
}

Check if you executing DatagridComponent more than once

Author

Commented:
Did you get in this order TRACE 1 then TRACE 2?

Yep
I got it like this

TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

TRACE 2:
Top Expert 2011

Commented:
How about constructor

Author

Commented:
when i run it without break points it doesnt display anything in the console.  any idea why
Top Expert 2011

Commented:
you just need to execute in debug mode, plus if mm.cfg is set on your local machine you shold able to get trace from a log file

Windows 7 path

C:\Users\royjayd\AppData\Roaming\Macromedia\Flash Player\Logs\flashlog.txt

Author

Commented:
1
TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\14 - 3,054 bytes after decompression
TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\15 - 3,054 bytes after decompression
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\16 - 3,054 bytes after decompression
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TRACE 2:


Top Expert 2011

Commented:
Now I understood.
I can see you created two DatagridComponent and may be first one is initialized but from your TextareaComponent class may not. Add one more trace into TextareaComponent constructor

public function TextareaComponent()  {
      super();
      trace(“BEFORE”);
      grid = new DatagridComponent();
      this.textArea.addEventListener(flash.events.KeyboardEvent.KEY_UP,callPopulate);
      trace(“AFTER”);
}

Author

Commented:

TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\10 - 3,054 bytes after decompression
BEFORE
TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\11 - 3,054 bytes after decompression
AFTER
TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\12 - 3,054 bytes after decompression
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\13 - 3,054 bytes after decompression
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TRACE 2:
Top Expert 2011

Commented:
Ok I can see constructor calls twice but why TRACE 1 4 times?

Author

Commented:
[Mediate(event="GlobalScreenEvent.LOOKUP_RECEIVED", properties="data")]
public function populateLookUp( data:Object ):void{
     lookupdataForFilter = data as ArrayCollection;  //contains the data
    trace("TRACE 1: " + lookupdataForFilter);
}


  populateLookUp() is called on this event GlobalScreenEvent.LOOKUP_RECEIVED...maybe swiz is calling it ?


Top Expert 2011

Commented:
From your logic it must be one constructor call and single TRACE 1 output.
You should fix it that how it will resolve your issue

Author

Commented:
i think because of
Swiz.dispatchEvent(new GlobalScreenEvent(GlobalScreenEvent.POPULATE_LOOKUP));

is in the DatagridComponent  constructor ?

so Trace 0 is invoked  3 times, Trace 1 is invoked 3 times, i checked again , trace 0  and trace 1 occurs three time..here is it

TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\13 - 3,054 bytes after decompression
BEFORE
TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\14 - 3,054 bytes after decompression
AFTER
TRACE 0
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\15 - 3,054 bytes after decompression
[SWF] C:\myWorkspace\TradeFlex\bin-debug\TradeFlex.swf\[[DYNAMIC]]\16 - 3,054 bytes after decompression

TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object]...
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object]...
TRACE 1: [object Object],[object Object],[object Object],[object Object],[object Object]...

...after Key is presed
TRACE 2:
Top Expert 2011

Commented:
Comment Swiz call check what's happend

public function DatagridComponent()
{
super();
 //Swiz.dispatchEvent(new GlobalScreenEvent(GlobalScreenEvent.POPULATE_LOOKUP));
}

Author

Commented:
i was actually trying to do this..put the swiz call in TextareaComponent  itself

public class TextareaComponent extends FormItem{
public function TextareaComponent()  {
super();
public var lookupdataForFilter:ArrayCollection = new ArrayCollection();
this.textArea.addEventListener(flash.events.KeyboardEvent.KEY_UP,callPopulate);
Swiz.dispatchEvent(new GlobalScreenEvent(GlobalScreenEvent.POPULATE_LOOKUP));
}

private function callPopulate(event: flash.events.KeyboardEvent) : void {
lookupdataForFilter = data as ArrayCollection;  
}

[Mediate(event="GlobalScreenEvent.LOOKUP_RECEIVED", properties="data")]
public function populateLookUp( data:Object ):void{
lookupdataForFilter = data as ArrayCollection;  
      }
}

But the problem is populateLookUp() is never called
Top Expert 2011

Commented:
Paste your controller implementation

Author

Commented:
     
public class LookupController extends 	import org.swizframework.controller.AbstractController;
	{
	[Mediate(event="GlobalScreenEvent.POPULATE_LOOKUP")]
		public function getLookUpData():void{
			var call : AsyncToken = delegate.getLookUpData();
			 
			executeServiceCall(call, lookupHandler, lookupFaulthHandler);											
		}	

		protected function lookupHandler(event:ResultEvent):void {
			if (isSessionValid(event))
			{
				Swiz.dispatchEvent(new GlobalScreenEvent(GlobalScreenEvent.LOOKUP_RECEIVED, event.result));
			}
		}
		
		public function lookupFaulthHandler ( fault : FaultEvent) : void {
			//trace("Unable to Fetch User List....");
		}
}

Open in new window

Author

Commented:
populateLookUp()  in DatagridComponent  is called but populateLookUp()  in TextareaComponent is never called..
Top Expert 2011
Commented:
Why are you executing getLookUpData twice?

[Mediate(event="GlobalScreenEvent.POPULATE_LOOKUP")]
public function getLookUpData():void

calling lookupFaulthHandler

"executeServiceCall(call, lookupHandler, lookupFaulthHandler);"

and lookupFaulthHandler calling back getLookUpData

by

"Swiz.dispatchEvent(new GlobalScreenEvent(GlobalScreenEvent.LOOKUP_RECEIVED, event.result));"

Explore More ContentExplore courses, solutions, and other research materials related to this topic.