Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

access data from one component to other component in actionscript

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
 
Avatar of dgofman
dgofman
Flag of United States of America image

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
Avatar of Jay Roy

ASKER

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
Did you get in this order TRACE 1 then TRACE 2?
public function DatagridComponent()
{
super();
trace("TRACE 0");
}

Check if you executing DatagridComponent more than once
Avatar of Jay Roy

ASKER

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:
How about constructor
Avatar of Jay Roy

ASKER

when i run it without break points it doesnt display anything in the console.  any idea why
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
Avatar of Jay Roy

ASKER

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:


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”);
}
Avatar of Jay Roy

ASKER


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:
Ok I can see constructor calls twice but why TRACE 1 4 times?
Avatar of Jay Roy

ASKER

[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 ?


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
Avatar of Jay Roy

ASKER

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:
Comment Swiz call check what's happend

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

ASKER

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
Paste your controller implementation
Avatar of Jay Roy

ASKER

     
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

Avatar of Jay Roy

ASKER

populateLookUp()  in DatagridComponent  is called but populateLookUp()  in TextareaComponent is never called..
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial