Titanium Alloy : How to pass several onClick events? - titanium-alloy

The following code :
<TableView id="tableview2" onClick="rowWasClicked ; goEdit" >
get me the following error message :
The event listener rowWasClicked ; goEdit is not defined.
More importantly, the function goEdit is never fired.
How to get both functions fired ?

If you want fired two onClick's events, a possible trick is:
<TableView id="tableview2" onClick="rowWasClicked" onClick="goEdit" >
With this code you can fire two onClick's events at the same time.

Related

In Flex how to refresh dataprovider on datagrid

Help me please...
I've a simple DataGrid, the dataprovider is a service "getServiceDatiResult.lastResult", this service is from webmethod aspnet that return a sqlserver data.
I created Event by click_button that insert data and get data into Datagrid....
The problem is the datagrid. It refresh data only when i call button event several times..
I ve tryed :
datagrid.refresh();
datagrid1.columns.clear();
datagrid1.columns.refresh();
getServiceDatiResult.lastResult.refresh();
getServiceDatiResult.lastResult.commit();
the code:
<mx:DataGrid id="datagrid1" creationComplete="datagrid1_creationCompleteHandler(event)"
dataProvider="{getServiceDatiResult.lastResult}" dropShadowVisible="true"
fontSize="12" fontWeight="normal" textAlign="center" verticalAlign="middle" editable="true">
<s:Button id="button3" label="Insdata3_now" click="button3_clickHandler(event)"/>
[Bindable]
protected function button3_clickHandler(event:MouseEvent):void
{
getServiceDatiResult.token = service.getServiceDati();
<!-- regresh ???? -->
getServiceDatiResult.lastResult.commit();
getServiceDatiResult.lastResult.refresh();
}
You want to refresh the DataGrid's dataprovider; which in turn will update the DataGrid.
Assuming you have an ArrayCollection, you can use the refresh() method to refresh all items:
(datagrid.dataProvider as ArrayCollection).refresh();
If you are only refreshing a single item, you can save some processing time by updating a single item with itemUpdated():
(datagrid.dataProvider as ArrayCollection).itemUpdated(item);
The MX DataGrid will take any object and try to display it in the DataGrid, so if you're getting an Array or XML returned from the server, you may have to replace the dataProvider:
datagrid.dataProvider = newDataProvider;
I agree with Reboogs solution. Another way of doing it is do, dataGrid.invalidatelist(), this is little heavy when compared to that of the dataprovider.refresh() as invalidation will reload and repaint the UI.
I think if you write this request calling correctly, refresh is not needed at all! For me, it looks like you are calling some async request, but maybe you asume its synchronous operation. I think is because of the [Bindable] tag at the handler method, why do you have it there?
But to decide I think you did not give us all information. For example - where is set variable getServiceDatiResult? you set some token inside, but what and where is set the lastResult?
I repeat I think just to call simple request, there is no need to refresh anything, the problem is elsewhere - handling the request itsef.
the (datagrid.dataProvider as ArrayCollection).refresh(); method is valid when you use Array like dataprovider ... In my case the problem is that click button(event) call 3 service that get update 3 different datagrid... So I 've 3 callresponder on 3 select to SqlServer by aspNet ... sincronize all operation is to much... my temporaney personal solution is modified Sql Table and reduce operation with click button(event) .. on this way datagrid update perfectly ... but i'm study a new solution ..thank you for help...
Just Refresh your data provider as follow,
var datapro:ArrayCollection = new ArrayCollection();
//
function dataRefresh():void
{
datapro.refresh();
}
//
//
<mx:DataGrid id="datagrid1" creationComplete="datagrid1_creationCompleteHandler(event)" dataProvider="{datapro}">
//
//

Gettiming "Implicit coercion of a value of type mx.events.FlexEvents to an unrelated type mx.events:ValidationResultEvent

In Flex mobile, I am trying to implement a validator for a TextInput field, but the compiler complains about the ValidationResultEvent I pass to the valid event handler:
It complains about this line:
<s:TextInput id="expiresIn__" paddingRight="10" valid="expiresInTxt_validHandler(event)" />
and for the event param passed to my valid handler, it says:
"Implicit coercion of a value of type mx.events:FlexEvent to an unrelated type mx.events:ValidationResultEvent."
I can't seem to find any answers to how to solve this on the internet. Is there some other way of doing this to make it work?
Your event handler should look something liker this:
protected function expiresInTxt_validHandler( e:ValidationResultEvent ):void
{
// handle it, yo.
}
To see the ValidationResultEvent constants, check here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/events/ValidationResultEvent.html

ASP.net: Code explanation of delegates and events

Given this code:
WriteThisMessageToThePage1.sendMessageToThePage += delegate(string message)
Can anyone explain me what this line means in delagates? What does this code represent?
+= is a short hand notation for subscribing to an event. The delegate(string message) code represents the event handler for the event. In this case the event handler is an anonymous method. When the sendMessageToThePage event fires, the code next += is executed.

Loader.loadBytes and getDefinitionByName

I am currently working on a project that will load a swc, inspect it and allow the user to view the classes inside.
I load the library.swf using Loader.loadBytes (the bytes come from the unzip library I use). I create an instance of the class using getDefinitionByName.
This all works fine as long as getDefinitionByName is called on the next frame. If I call it straight away I get a reference error. To get round this I've come up with a rather hacky solution:
private function processLibraries( event : Event ) : void
{
_zipFiles.forEach( processSwfs );
DisplayObject( FlexGlobals.topLevelApplication ).addEventListener( Event.ENTER_FRAME, enterFrame );
}
private function enterFrame( event : Event ) : void
{
DisplayObject( FlexGlobals.topLevelApplication ).removeEventListener( Event.ENTER_FRAME, enterFrame );
_classCollection = new ArrayCollection();
_zipFiles.forEach( processCatalogs );
complete( _classCollection );
}
I really don't like using the enter frame event on the top level application. I also don't want to have to set up a timer. That's just as nasty.
Loader.loadBytes doesn't fire a complete event so I don't know where I listen for an event for when the bytes have been fully loaded into the ApplicationDomain.
There must be a neater way round this?
Thanks
Loader.loadBytes does fire a complete event. Remember to add your listener to Loader.contentLoaderInfo.
However, if you are loading a SWF file which was part of a SWC file compile with a FlexSDK prior to version 4 you will not get the Event.INIT method since it is only fired when a document class is availalable. Such a class is injected by the compiler since SDK version 4.

Flex Script and Event Question

I wonder how to achieve this in Flex.
Basically, I have enabled Drag and Drop in some of my list controls.
<mx:DataGrid id="dg1" width="100%" height="100%" dataProvider="{xmllcData}"
dropEnabled="true" dragDrop="dg1_dragDropHandler(event)">
</mx:DataGrid>
In the function dg1_dragDropHandler event, I have the following codes:
private function dg1_dragDropHandler(evt:DragEvent):void
{
// Perform some actions here...
// .......
// Show Message to Confirm.
Alert.show('Proceed?', 'Title', Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES);
}
private function handleAlert(evt:CloseEvent):void
{
if (evt.detail == Alert.YES)
{
// Perform the functions as necessary
}
else
{
// Execute the script to prevent the dropping of the object.
// How can I call the DragEvent.preventDefault(); function from here?
}
}
In the codes above, I want to call the preventDefault() on the alertHandler function since the other scripts after the call to the Alert.show in dg1_dragDropHandler event would be executed concurrently with the alert.show.
How would I be able to reference the DragEvent of the dg1_dragDropHandler event from the alertHandler event?
Instead of specifiying your listener function, handleAlert(), as a normal function, you can use an anonymous function. Write your code like this:
private function dg1_dragDropHandler(evt:DragEvent):void
{
// Perform some actions here...
// .......
// Show Message to Confirm.
Alert.show('Proceed?', 'Title',
Alert.YES | Alert.NO,
null,
function(evt:CloseEvent) {
if (evt.detail == Alert.YES) {
// Perform the functions as necessary
}
else {
// Execute the script to prevent the dropping of the object.
// Now you have access to the evt:DragEvent!
}
},
null, Alert.YES);
}
}
When you use an anonymous function, you still have access to all the variables in your current scope. This means you can still access the evt:DragEvent variable. As Glenn said though, I don't know if this will solve your default action problem.
You probably want to store the details of the dropEvent in a local variable. Then when you want to do your "preventDefault" part, just access the event object and do your magic.
Not sure why you want to preventDefault though. I'm not quite understanding that part. Wouldn't all the other listeners of the event run to completion while the program is waiting for you to say YES/NO to the alert?
Which other parts of the callstack are operating here? You could stop anything else in the event chain from happening by calling event.stopImmediatePropergation(); on the first line of your dragDropHandler (assuming that the listener has a higher priority than others in the chain).
You would then need to manually replicate the drag and drop operations on confirm, which I'm not sure but you could achieve using the doDrag() method of the DragManager.
DragManager.doDrag() langauge reference
You're absolutely right that the Alert will be popped up asynchronously with respect to the original DragEvent dispatch.
Since you don't want the default datagrid behavior to kick in at that point, you need to call preventDefault() on receipt of the event, and then throw up your alert panel.
Then, in the success branch of your alert handler, you could try to rethrow ( throw a new) DragEvent. Use a local variable to keep track of the original event details so that you can clone() or simply create a new event with the same properties. Basically, you're intercepting and interrupting the event flow and then attempting to resume it later.
Haven't tried this myself, but that's what I'd explore first.
I have not tried this myself, but preventing default behavoiur immediately is the only way to stop the grid from performing the copy or move.
Try preventing the default behaviour and maintaining the drag event. Then, if you user hits no, you have already stopped the event. If the user hits yes, you can (this is the part i am unsure of) re-dispatch the drop event on the grid. Hopefully it will behave normally. To get the event into your Alert handler you can simply use the data property on the Event window to track it.
private function dg1_dragDropHandler(evt:DragEvent):void
{
// Perform some actions here...
// .......
evt.preventDefault();
// Show Message to Confirm.
Alert.show('Proceed?', 'Title', Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES).data = evt;
}
private function handleAlert(evt:CloseEvent):void
{
if (evt.detail == Alert.YES)
{
// Perform the functions as necessary
var dgEvt:DragEvent = Alert(evt.currentTartet).data;
var newDrag:DragEvent; //need a new event because the default behaviour on the old one is still prevented
//copy event values to new drag event
dg1.dispatchEvent(newDrag);
}
else
{
// Execute the script to prevent the dropping of the object.
// How can I call the DragEvent.preventDefault(); function from here?
}
Again, not entirely sure if it will work, just off the top of my head. Of course, you have to remove the custom dragDrop event handler from your grid before you redispatch the approved drag, otherwise your handler with prevent the default, then pop an alert and repeat over and over.

Resources