In Flex, event handlers must be defined with an event parameter.
This event parameter is not necessarily used in the event handler.
See http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html
That leads to "false positives" against flex:S1172 - Unused function parameters should be removed.
Is there anything you could do about it?
See the following JIRA ticket: http://jira.sonarsource.com/browse/SONARFLEX-52
Related
I have a function which handles tracking of a certian event, like so:
var trackAddress = function (providedProduct, searchedProduct) {
_trackEvent('Address found', providedProduct, searchedProduct);
}
Now what will happen if searchedProduct is undefined or an empty string?
The thing is, in Google Analytics I can see that the sum of all event actions is equal to the total number of events. That is not the case in event labels.
What could be the cause for this?
I'm sure you know this, but for the sake of argument this is the anatomy of an event tracker:
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
category (required): The name you supply for the group of objects you want to track.
action (required): A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
label (optional): An optional string to provide additional dimensions to the event data.
value (optional): An integer that you can use to provide numerical data about the user event.
non-interaction (optional): A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation.
Now in case a required parameter is missing (like action in your case) there's must be a mechanism within Google Analytics that will invalidate the event altogether. Conversely, an optional parameter, won't affect the event tracking but rather the report. To sum up, the result is the same: Loss of data.
A possible way around this to provide default parameters for your function arguments like so:
providedProduct = typeof a !== 'undefined' ? providedProduct : "defaultValue";
Further Reading: Setting Up Event Tracking
I've just the documentation on the Qt event system and the QEvent class. I'm interested in the behavior of the QObject::event() method. The documentation states:
This virtual function receives events to an object and should return true if the event e was recognized and processed.
What is the expected behavior when false is returned from the event() method? What else is attempted in order to handle the event? Is the event automatically forwarded to the parent object?
Note: I know the source is available, and I do have a copy. I'm ideally looking for some piece of documentation addressing this behavior.
I believe the best practice is to explicitly forward the events to the base-class event method if you do not wish to filter that event type (e.g. return QObject::event(event);) since the event function delegates events to specific handlers (e.g. QWidget::keyPressEvent).
QCoreApplication::notify propogates events based on the return value. On true, it considers the event as consumed and stops. Otherwise, the event is passed to the object's parent. For more information, see Events and Filters and Another Look at Events.
Some Events can be propagated.Event will be propagated to it's parent and it's parent recursively until it is processed. Take a look at this:https://doc.qt.io/archives/qq/qq11-events.html
In my AIR application (with mate-Framework) i did follwing things:
click on a button
call a method in my model "onApplicationBusy"
apply some filter in arraycollections.
In my onApplicationBusy there is this code:
FlexGlobals.topLevelApplication.enabled = false;
FlexGlobals.topLevelApplication.
I trace every step and all methods are called in right order.
But my application never becomes disabled.
Why. Is there a method for this purpose.
I try InvalidateDisplayList or ValidateNow or callLater. But all tries won't work. Probably i try it on the wrong place?
I assume, my application is so busy while applying filters (4 values for 10.000 lines) that the disabled property can't processed.
If i call the method without applying the filters all works fine.
If i call just the disbaled property but never enable the app again, the app will shown as disabled after applying the filters. for me too late.
What i origin want is a clear behavior, when the app is busy and when not (ready for clicking on buttons and all this stuff).
If you can help me or know a method, how can i shown a busy application, please help me
Thanks
Frank
All right, the setTimeout Method solve my issue. I assume, I have to wait for the next screen refresh.
Why callLater won't work and when i have to implement those functions, because i have too less ressources while my filterFunction is running?
Frank
I'm using FlexGlobals.topLevelApplication.stage.mouseChildren = false | true;
Worth noting that I first tried setting the mouseEnabled flag but found various visual elements would not update at all while mouseEnabled = false.
How can I tell what the default behavior for a cancelable event is?
For example, I read somewhere that the TextEvent.TEXT_INPUT has a default behavior and that default behavior includes adding a text character associated with the key that was pressed to a TextInput. That makes perfect sense.
But if I hadn't read that, how would I know what the default behavior is? Other than guessing. In this case, it's probably obvious. But in other situations, it might not be.
For example, in the docs, look at DataGridEvent.HEADER_RELEASE's cancelable property. It says:
cancelable: true
so, there appears to be a "default behavior" associated with a DataGridEvent.HEADER_RELEASE event. But what is it? And why would I cancel it if I'm not really sure what it is? :)
thanks.
It's all in the documentation, which says: "The DataGrid control has a default handler for this event that implements a single-column sort."
The live docs a pretty thorough. If you keep following the links you'll usually find what you are looking for.
Here's what I think to be true -
To cancel the default behavior associated with an event, 2 things must be true:
The event must be marked as cancelable (you can check the event's cancelable property to determine this). If you are dispatching the event yourself, set the 3rd parameter to true to mark the event as cancelable. If the event is marked as cancelable, calling event.preventDefault() will set the event to "cancelled" and a query of event.isDefaultPrevented() will return true. If the event is NOT marked as cancelable, calling event.preventDefault() will do nothing at all. A query of event.isDefaultPrevented() will always return false no matter how many times you call event.preventDefault().
The event handler registered for the event must actually have the ability to do nothing (i.e. prevent the default behavior associated with the event). So the handler must have something like this in it:
if (!event.isDefaultPrevented()) { doSomething(); }
So, that still leaves me with the question - "For a cancelable event of type X, what is the default behavior?"
I guess that depends on the target of the event. For example, the target of a DataGridEvent.HEADER_RELEASE event is a DataGrid and inside the DataGrid class you'll find this in the constructor:
addEventListener(DataGridEvent.HEADER_RELEASE,
headerReleaseHandler,
false, EventPriority.DEFAULT_HANDLER);
and the handler looks like this:
private function headerReleaseHandler(event:DataGridEvent):void
{
if (!event.isDefaultPrevented())
{
manualSort = true;
sortByColumn(event.columnIndex);
manualSort = false;
}
}
Or, you can poke around aimlessly in the docs forever and maybe stumble on the answer like this:
http://livedocs.adobe.com/flex/3/langref/mx/controls/DataGrid.html#event%3aheaderRelease
"The DataGrid control has a default handler for this event that implements a single-column sort"
Hopefully, this answer helps reduce the aimlessness of your doc search.
Jeremy
printableInvoice.addEventListener(batchGenerated, printableInvoice_batchGeneratedHandler);
Results in this error:
1120: Access of undefined property batchGenerated. I have tried it as FlexEvent.batchGenerated and FlashEvent.batchGenerated.
The MetaData and function that dispatches the even in the component printableInvoice is all right. It I instantiate printableInvoice as an mxml component instead of via action-script it well let put a tag into the mxml line: batchGenerated="someFunction()"
Thanks.
batchGenerated should be a string.
It looks like your application dispatches an event whenever the batch is generated.
I'm assuming inside your code you have something along the lines of either:
dispatchEvent( new BatchEvent("batchGenerated") );
or
dispatchEvent( new BatchEvent(BatchEvent.BATCH_GENERATED) );
The second way is usually preferred as using variables instead of magic strings gives you an extra level of compile time checking.
The first required parameter of events is typically the type of the event - Event.CHANGE (aka "change"), FlexEvent.VALUE_COMMIT (aka "valueCommit") etc.
This is what the event listener is actually comparing against.
So in your event listener code above, you would want to change the line to be either:
printableInvoice.addEventListener("batchGenerated", printableInvoice_batchGeneratedHandler);
or hopefully
printableInvoice.addEventListener(BatchEvent.BATCH_GENERATED, printableInvoice_batchGeneratedHandler);
If you want to go further, the Flex documentation goes into some detail as to how the event system works, and how the events are effectively targeted and handled through the use of the Capture, Target, and Bubble phases.