How to taken push view object into next view in flex - apache-flex

My problem is that when I try to pass an object from the navigator.pushView(view, dataobject), I can't figure out how to access the dataobject from actionscript. I can access {dataobject.property} from MXML easily, but I want to set a variable in the new view to the passed dataobjects property.

You have the passed object available in 'data' property. You can easily set your new local variable in activateHandler as:
var myVar:String = data.myPassedVar;

Related

How can i make an object unmodifiable in flex

I am having a configuration object in my flex3.5 application. I want that object to be unmodifiable so that no one can change any property in it once it is created.
If you're talking about a generic Object, it's impossible since it's dynamic. What you want to do is create a class that has only 'getter' functions and every property is specified in the constructor.
If you want to have it still bindable, look at my blog post about bindable read-only properties.
Use get/set methods. There is can be two strategies:
Private variables are initialized within class itself and every private variable has public get-method which makes public field read only.
If you need to set values from outside you should create set-methods and throw an error if value already set.

set dataprovider in actionscript

I have a datagrid w/ dataProvider property set in MXML as:
dataProvider="{pagedResult.lastResult}"
How do I set the dataprovider in actionscript? I have:
protected function getResult (event:FlexEvent):void
{
pagedResult.token = mydata.paged();
adg1.dataProvider = pagedResult.lastResult;
}
but I'm doing something wrong as it does not work
Your code looks solid, I guess the issue is that you need to convert it. You didn't say what sort of data your service is returning, but for the purposes of this sample I'll assume an Array
Try something like this
var myCollection : ArrayCollection = new ArrayCollection(pagedResult.lastResult as Array);
adg1.dataProvider = myCollection;
First if you are going to set the dataProvider from Actionscript I would remove the binding from the MXML, or you could just update the property that is bound but I do not know it's type so I will assume you have no problem removing the binding from the MXML tag.
Second as another answer mentioned you will want to convert your results to an ArrayCollection, you can find some useful functions in the mx.utils.ArrayUtil class.
Lastly it is important when working with large datasets you should update the ArrayCollection directly rather than always creating a new one. The list/datagrid will automatically redraw and update, optimally, without you having to worry about it as long as you add/remove/etc through your newly created ArrayCollection.

ASP.NET Reflection get typeof current object

I am working on a project where all of our object have a standard base class. We just added some new fields to the database for the tables behind some of the objects e.g. "DateCreated".
I would like to use reflection on the base class' insert method so that when it is called it checks the object to see if it has a property "DateCreated" and if it does sets it to DateTime.Now
The problem I'm having is typeof(this) does not work and I don't know what the type is in the base class obviously.
Is it possible to get the PropertyInfo typeof for an object from within the object without hard coding the object type or using a generic?
You can use this.GetType() in the base and receive the Type of the derived class.

Is a DropShadowFilter mutable in Flex 3.5?

I have a dropfilter defined using some bindable variables as parameters.
<mx:filters>
<mx:DropShadowFilter id="torinofilter" distance="0" color="{dropShadowColor}"
blurX="{dropBlur}" blurY="{dropBlur}" strength="8" quality="2"
alpha="{dropAlpha}"/>
</mx:filters>
I would like to update the filter in a method call like this:
this.dropShadowColor = <new color>
this.dropBlur = 15.0;
this.dropAlpha = 0.8;
Upon tracing both this.dropShadowColor and torinofilter.color, I see they have updated to the new color, but the color of the dropfilter doesnt change.
I would prefer not to create a new filter because then I get issues with swapChildren.
Properties of filters cannot be modified like this.
To modify an existing filter object, you must use the technique of modifying a copy of the filters array:
Assign the value of the filters array to a temporary array, such as one named myFilters.
Modify the property by using the temporary array, myFilters. For example, to set the quality property of the first filter in the array, you could use the following code: myFilters[0].quality = 1;
Assign the value of the temporary array to the filters array.
Basically when you read filters array of a DisplayObject, flash returns a copy of the array, not the live filters array. Pushing a new filter or updating existing filters will only modify the copy, not the original; you have to assign it back to the array to reflect the changes.
Do this from actionscript instead of mxml.
I would prefer not to create a new filter because then I get issues with swapChildren.
swapChildren applies only to display objects (UIComponents in case of flex containers).

Getting handles to dynamically-generated Flex components

I have a Flex application which references a separate MXML file as a template for a custom component. I create instances of the component dynamically several times in my program, but I need to get a handle that will allow me to modify that instance of the component as desired.
I pass specific information to this component on instantiation using bindable public variables in the component's MXML file. I add it to my main program using addChild().
I want to update the component's progressbar as necessary and I want to remove it from the box to which I addChild'd it.
What's the easiest/best way to get a variable that will give me predictable access to each component so I can easily manipulate the components as necessary? Some research suggests creationComplete, but I decided it was faster to just ask than to go through lots of different experiments and come up blank.
Thanks for all the help. : )
Can you not just keep a list of your components in an array? Presumably you have an object reference when you create them and call addChild() on their parent. Why not just put them in an array at the same time?
var list_of_controls:Array = new Array();
var new_Object:<yourType>;
new_Object = new <yourType>();
parent.addChild(new_Object);
list_of_controls.push(new_Object);
then you can get at them...
var my_Object:<yourType>;
for each (my_Object in list_of_controls)
{
// do something
}
You would have to make sure you dispose of them properly when you re done because the reference in your array would keep them in existence until cleared.
If you decide that you want to use getChildren() instead - which you could - take the time to read the documentation because I think it returns a new array with each call.
I hope that helps.

Resources