Removing dynamically created component causes error - apache-flex

I have problem with casting custom event currentTarget to component. When I'm trying to removeElement from its parent container i get error. What's the deal?
TypeError: Error #1034: Type Coercion failed: cannot convert mx.events::FlexEvent#8811c41 to com.modultek.pis.itemmachine.search.events.SortEvent.
private function sortSelection_removeHandler(event:SortEvent):void
{
var sortSelection:SortSelection = event.currentTarget as SortSelection;
this.removeElement(sortSelection);
}
Component will be removed but I get this error.

your problem is not in the var sortSelection:SortSelection = event.currentTarget as SortSelection; line at all.
Read the Error message carefully. It tells you that there is an invalid cast from FlexEvent to SortEvent, which happens on
private function sortSelection_removeHandler(event:SortEvent):void
Change event:SortEvent in the function signature to event:FlexEvent or event:Event

Problem was that I didn't have event declaration on my dispatching class.
[Event(name="remove" , type=".....search.events.SortEvent")]

Related

null object reference while call other compenet function

I have create the following function in component A(which is productDetailComp)
public function createProductDetailItem(productdetail:Productdetail):void{
productdetailService.createProductdetail(productdetail);
productdetailService.commit();
}
and in the component B, I call the function via
var productdetail:Productdetail = new Productdetail();
productDetailComp.createProductDetailItem(productdetail);
but, why the following error pop up while invoking the createProductDetailItem() function? Need to create a instance for the function or the component productDetailComp??
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at productDetailComp/onEdit()[C:\Users\School\Adobe Flash Builder 4.6\FYPadminSideV3\src\productDetailComp.mxml:80]
at productDetailComp/__button2_click()[C:\Users\School\Adobe Flash Builder 4.6\FYPadminSideV3\src\productDetailComp.mxml:250]

Error During Print

There are a three public variable
public var objPrintJob:FlexPrintJob;
public var objPrintTemplate:canvas;
Fn1:
objPrintJob = new FlexPrintJob();
if (objPrintJob.start() != true)
{
printCount--;
return;
}
Starting the PrintJob;
Fn2:
Am adding the Object and calling send for the Print
objPrintJob.addObject(objPrintTemplate, FlexPrintJobScaleType.SHOW_ALL);
objPrintJob.send();
During Run
It Throws the Error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.printing::FlexPrintJob/addObject()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\printing\FlexPrintJob.as:252]
at org.dckap.mafcote.views.mediators::WorkAreaMediator/parseXML()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\mediators\WorkAreaMediator.as:3243]
at org.dckap.mafcote.views.mediators::WorkAreaMediator/onSaveTemplateWithCredits()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\mediators\WorkAreaMediator.as:2896]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at org.dckap.mafcote.views::CreditsShowPanel/okButtonClickHandler()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\CreditsShowPanel.mxml:41]
at org.dckap.mafcote.views::CreditsShowPanel/__btnOk_click()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\CreditsShowPanel.mxml:159]
Need Help For This..
}
This has to be that your objPrintTemplate object is null. The stack trace in your error shows that it's erroring in FlexPrintJob/addObject(), which means it made it into that method but did not complete executing the method. Since the only parameters you're sending to it are your object reference and a constant value, the object must be null.
After your support I found out my solution.
Thank U all.
The object does not seems to be null.
I did one mistake that is i didn't added the object as a child anywhere else.
so the addObject() in print requires the systemManager.
which will be null if i didn't add as a child.
Thank You for your support

ASP.NET AJAX: How to access object properties?

My web method returns object 'User' that has a lot of properties.
In my 'OnComplete' function I am receiving those object.
function OnComplete(args) {
var res = $get('WsResult');
debugger;
res.innerHTML = args['Nick'];
}
Question: How can I get values of object properties?
The code above provides me with '[object Object]' text instead of real object value.
Thanks a lot!
You can get these properties the same way you get any other properties:
alert(args.Nick.FullName);

Array subclasses cannot be deserialized, Error #1034

I've just found a strange error when deserializing from a ByteArray, where Vectors cannot contain types that extend Array: there is a TypeError when they are deserialized.
TypeError: Error #1034: Type Coercion failed: cannot convert []#4b8c42e1 to com.myapp.ArraySubclass.
at flash.utils::ByteArray/readObject()
at com.myapp::MyApplication()[/Users/aaaidan/MyApp/com/myapp/MyApplication.as:99]
Here's how:
public class Application extends Sprite {
public function Application() {
// register the custom class
registerClassAlias("MyArraySubclass", MyArraySubclass);
// write a vector containing an array subclass to a byte array
var vec:Vector.<MyArraySubclass> = new Vector.<MyArraySubclass>();
var arraySubclass:MyArraySubclass = new MyArraySubclass();
arraySubclass.customProperty = "foo";
vec.push(arraySubclass);
var ba:ByteArray = new ByteArray();
ba.writeObject(arraySubclass);
ba.position = 0;
// read it back
var arraySubclass2:MyArraySubclass = ba.readObject() as MyArraySubclass; // throws TypeError
}
}
public class MyArraySubclass extends Array {
public var customProperty:String = "default";
}
It's a pretty specific case, but it seems very odd to me. Anyone have any ideas what's causing it, or how it could be fixed?
well, it seems array serialization is hardcoded. you should definitely post a bug report.
actually the code you posted doesn't throw an error since ba.readObject() as MyArraySubclass is simply null. MyArraySubclass(ba.readObject()) however would.
what you could try to fix it, would be to implement IExternalizable, altough I'm not sure it'll work any better.
I guess the problem is that Array is a very very special class in ActionScript (in the sense that in some way it is nothing more than any other dynamic class, but in other ways it's not at all) which leads to a lot of Array-specific code in the VM. Also, a question is, why do you need to subclass Array?

Binding to a read-only getter in AS3

Consider the following code:
[Bindable(event="ReportHeaderVO_effectiveFromDateJulian_updated")]
public function set effectiveFromDateJulian ( value:Number ) : void
{
_effectiveFromDateJulian = value;
dispatchEvent( new FlexEvent("ReportHeaderVO_effectiveFromDateJulian_updated") );
}
public function get effectiveFromDateJulian () : Number
{
return _effectiveFromDateJulian;
}
public function get effectiveFromDate () : Date
{
return DateUtil.convertJDEJulianToDate(_effectiveFromDateJulian);
}
There is a setter and a getter for the effectiveFromDateJulian which is a number representation of the date. I have provided a seperate getter which retrieves the same value, only converted to a proper date. It is a getter only though and relies on the setter for the numeric property to get its data from; so the effectiveFromDate property is effectively read-only.
Data binding works on the effectiveFromDateJulian property; any updates work fine and notify everything properly. But when binding to the effectiveFromDate (getter only) property, I get a warning from the compiler:
warning: unable to bind to property 'effectiveToDate' on class 'com.vo::ReportHeaderVO'
Is there a way to make it possible to bind to this read-only property? I would assume I would have to dispatch an event on the setter that effects the read-only property, but I don't know what that would look like.
This is a simple example, you could imagine a read-only property that depends on several setters to function and when any of those setters are updated the read-only property would need to fire a propertyChanged event as well. Any ideas? Please let me know if I need to clarify anything.
Update:
From the Adobe documentation here:
http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.html
Using read-only properties as the
source for data binding
You can automatically use a read-only
property defined by a getter method,
which means no setter method, as the
source for a data-binding expression.
Flex performs the data binding once
when the application starts.
Because the data binding from a
read-only property occurs only once at
application start up, you omit the
[Bindable] metadata tag for the
read-only property.
And this makes sense for constant values, but in this case the value does change, it just doesn't get set directly.
Make the readonly getter Bindable and dispatch the corresponding event from the original setter method.
[Bindable(event="ReportHeaderVO_effectiveFromDateJulian_updated")]
public function set effectiveFromDateJulian ( value:Number ) : void
{
_effectiveFromDateJulian = value;
dispatchEvent( new FlexEvent("ReportHeaderVO_effectiveFromDateJulian_updated") );
dispatchEvent( new FlexEvent("ReportHeaderVO_effectiveFromDate_updated") );
}
[Bindable(event="ReportHeaderVO_effectiveFromDate_updated")]
public function get effectiveFromDate (date:Date) : Date
{
return DateUtil.convertJDEJulianToDate(_effectiveFromDateJulian);
}

Resources