Jay Roy
asked on
this.parentDocument for actionscript file
hi guys
I have a line like this
var searchString : String = (this.parentDocument as TradeLookUp).parseSearchTe xt();
TradeLookUp is mxml file.
I have an actionscript file CustomLookup
but when i give
var searchString : String = (this.parentDocument as CustomLookup).parseSearchT ext();
i get an error.
i guess this.parentDocument works with mxml
any idea whats the solution
thanks
I have a line like this
var searchString : String = (this.parentDocument as TradeLookUp).parseSearchTe
TradeLookUp is mxml file.
I have an actionscript file CustomLookup
but when i give
var searchString : String = (this.parentDocument as CustomLookup).parseSearchT
i get an error.
i guess this.parentDocument works with mxml
any idea whats the solution
thanks
ASKER
actually i am getting an error
on this line
var searchString : String = (this.parentDocument as CustomLookup).parseSearchT ext();
The error is
TypeError: Error #1009: Cannot access a property or method of a null object reference.
on this line
var searchString : String = (this.parentDocument as CustomLookup).parseSearchT
The error is
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Did you read what I am suggestion?
replace by
trace("Is CustomLookup=" + this.parentDocument is CustomLookup);
var lookup: CustomLookup= this.parentDocument as CustomLookup;
trace("Is accessible to parseSearchText="+lookup.h asOwnPrope rty("parse SearchText "));
var searchString : String = lookup.parseSearchText();
replace by
trace("Is CustomLookup=" + this.parentDocument is CustomLookup);
var lookup: CustomLookup= this.parentDocument as CustomLookup;
trace("Is accessible to parseSearchText="+lookup.h
var searchString : String = lookup.parseSearchText();
ASKER
Hi i tried this and getting this responce in console
trace("Is CustomLookup=" + this.parentDocument is CustomLookup);
false
var lookup: CustomLookup= this.parentDocument as CustomLookup;
trace("Is accessible to parseSearchText="+lookup.h asOwnPrope rty("parse SearchText "));
getting error here: TypeError: Error #1009: Cannot access a property or method of a null object reference.
var searchString : String = lookup.parseSearchText();
thanks
trace("Is CustomLookup=" + this.parentDocument is CustomLookup);
false
var lookup: CustomLookup= this.parentDocument as CustomLookup;
trace("Is accessible to parseSearchText="+lookup.h
getting error here: TypeError: Error #1009: Cannot access a property or method of a null object reference.
var searchString : String = lookup.parseSearchText();
thanks
You got answer in first trace. You are customhouse to wrong class. Check what type of parentDocument
ASKER
yeah.Actually this is what i am doing
In CustomLookup.as i am using this code
/**
* Prepares the datagrid column from dataFieldCollection.
* */
public function createDataGridColumns () : void {
columns = new Array();
for each (var object : Object in dataFieldCollection){
var col : DataGridColumn = new DataGridColumn();
col.headerText = object.headerText;
col.dataField = object.dataField;
col.width = object.width;
if ( object.dataField != CHECKHBOX ) {
col.itemRenderer = new ClassFactory ( org.ms.views.components.re nderers.DataLabelForGrid );
} else {
col.itemRenderer = new ClassFactory ( org.ms.views.components.re nderers.Se lectCheckB ox );
}
columns.push( col );
}
dataGrid.columns = columns;
}
and in DataLabelForGrid.mxml i have
<?xml version="1.0" encoding="utf-8"?>
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasse s.DataGrid ListData;
import mx.core.Application;
import org.ms.views.components.Cu stomLookup ;
override public function set data ( value : Object ) : void {
super.data = value;
var strData : String = value as String;
var labelString : String = value[DataGridListData(lis tData).dat aField] as String;
trace("parent doc=" + this.parentDocument);
//here i want this.parentDocument to be CustomLookup
Any idea how i can make this.parentDocument as CustomLookup ?
if (searchString.text = "jay") {
this.setStyle( "color", "yellow" );
}
}
]]>
</mx:Script>
</mx:Label>
In CustomLookup.as i am using this code
/**
* Prepares the datagrid column from dataFieldCollection.
* */
public function createDataGridColumns () : void {
columns = new Array();
for each (var object : Object in dataFieldCollection){
var col : DataGridColumn = new DataGridColumn();
col.headerText = object.headerText;
col.dataField = object.dataField;
col.width = object.width;
if ( object.dataField != CHECKHBOX ) {
col.itemRenderer = new ClassFactory ( org.ms.views.components.re
} else {
col.itemRenderer = new ClassFactory ( org.ms.views.components.re
}
columns.push( col );
}
dataGrid.columns = columns;
}
and in DataLabelForGrid.mxml i have
<?xml version="1.0" encoding="utf-8"?>
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasse
import mx.core.Application;
import org.ms.views.components.Cu
override public function set data ( value : Object ) : void {
super.data = value;
var strData : String = value as String;
var labelString : String = value[DataGridListData(lis
trace("parent doc=" + this.parentDocument);
//here i want this.parentDocument to be CustomLookup
Any idea how i can make this.parentDocument as CustomLookup ?
if (searchString.text = "jay") {
this.setStyle( "color", "yellow" );
}
}
]]>
</mx:Script>
</mx:Label>
In DataLabelForGrid.mxml create public variable
public var lookup:CustomLookup;
Now modify you CustomLookup.as
if ( object.dataField != CHECKHBOX ) {
var cf:ClassFactory = new ClassFactory ( org.ms.views.components.re nderers.Da taLabelFor Grid );
cf.properties = {lookup:this};
col.itemRenderer = cf;
} else {
That should assign lookup variable during constractor
now you can use "lookup" variable in your DataLabelForGrid.mxml
I didn't compile but should work
public var lookup:CustomLookup;
Now modify you CustomLookup.as
if ( object.dataField != CHECKHBOX ) {
var cf:ClassFactory = new ClassFactory ( org.ms.views.components.re
cf.properties = {lookup:this};
col.itemRenderer = cf;
} else {
That should assign lookup variable during constractor
now you can use "lookup" variable in your DataLabelForGrid.mxml
I didn't compile but should work
ASKER
nice, but i did not understand how it works :)
cf.properties = {lookup:this}; what does this line do ?
>>That should assign lookup variable during constractor
so lookup is assigned to CustomLookup in constructor of CustomLookup ?
thanks
cf.properties = {lookup:this}; what does this line do ?
>>That should assign lookup variable during constractor
so lookup is assigned to CustomLookup in constructor of CustomLookup ?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANKS!
Can be two problems:
1) parentDocument is not instance of CustomLookup
add one line above trace(parentDocument );
2) in CustomLookup.as file you don't have public function parseSearchText
you can validate by:
var lookup: CustomLookup= this.parentDocument as CustomLookup;
trace(lookup.hasOwnPropert