Bindable function without event name specified - actionscript-3

What is the effect of making a function Bindable in flex without specifying event name with it? I have done this in my code and it seems to be working alright without any associated event (however it does generate a warning). If I remove the binding from such functions it will does effect the code and doesnt reflect the changes if the return value from the function changes.
Could someone explain me , how and why such Bindable function work even without any event associated with [Bindable] tag.
Example:
<mx:Image id="a" source="{getImage(1)}" useHandCursor="true" buttonMode="true" width="10" height="10" click="finalize(event)" autoLoad="true"/>
[Bindable] private var _ratingSelected:int;
[Bindable]
private function getImage(value:int):String
{
if (value <= _ratingSelected)
return 'images/hr/applicants/star_icon.png';
else
return 'images/hr/applicants/star_icon_dis.png';
}
If I remove the Bindable tag from getImage function here, the image doesnt properly get updated at the run time. Please note that _ratingSelected is Bindable variable here. Even though I don't have any event associated with getImage() function, making it Bindable seems to be working just alright. Does it automatically detect changes to changes in _ratingSelected variable (which is bindable) and call the getImage function at run time? Kindly enlighten.
Thanks.

When you don't specify an event name in the Binding tag, it uses the event "propertyChange". This means that every time the framework gets a "propertyChange" event from your document, it'll try to update the image source by calling getImage again.
Now when the value of _ratingSelected is updated, a "propertyChange" event is dispatched internally, which then causes the image to be updated.
Note that this has nothing to do with whether getImage actually uses _ratingSelected to generate its return value. The only connection between getImage and _ratingSelected from the data binding framework's point of view is the "propertyChange" event which they both claim to dispatch when their respective values have changed (even though getImage never actually dispatches it).

Related

How to deactivate onTick method in Cesium

I have Problem with onTick() method, I have two buttons for two different situations, in each one I will load separate dataSource, just like the czml.html example on Sandcastle. I have two different definition for onTick() method for each button seperately, to do some specific things when we reach at a specific time. In the reset method I am removing entities and dataSources of my viewer, but I cannot remove onTick method implementation.
When I am running my code, the default button is doing perfectly fine, but when I press other button, all those conditions that I mentioned for the first button is also happening at the same time, and it will not let my second onTick method to perform its job correctly. Do you know how I can deactivate the first onTick method?
Take a look at the addEventListener documentation, you'll find two different ways to undo the addition of an event listener: One is to call the matching removeEventListener, and the other is to save the return value from addEventListener and invoke it later.
Here's some code showing both ways. Use whichever option makes more sense for your code, but don't use both at once.
function onTickCallback(clock) {
// ... do stuff with every tick ...
}
var unsubscribeTicks = viewer.clock.onTick.addEventListener(onTickCallback);
function unsubscribeOption1() {
// One option is to call removeEventListener. In this case, you
// don't need to save "var unsubscribeTicks" at all, but you do
// need a reference to the original onTickCallback.
viewer.clock.onTick.removeEventListener(onTickCallback);
}
function unsubscribeOption2() {
// The other option is to save the return value of addEventListener,
// and later invoke it. This could be a cleaner option if the
// onTickCallback was declared anonymously inline.
unsubscribeTicks();
}

GWT event that should be fired whenever textbox.setText() is called

I am using GWT textbox.
Whenever textbox.setText() method is called, i want to perform an action in some other class.
ValueChangeEvent is not fired whenever setText() is called.
Is there any event that will be fired or any ways to achieve this?
Please help
You could try to use setValue(String value, boolean fireEvent) method
If you have a look at the TextBox.seText() method, you'll see that, all the way down to the actual DOM, no event is ever generated, so what you want to do simply won't work off-the-box.
I see two options:
Whenever you call setText, you also call the event handler of your choice or, much better
Make your own TextBox that extends TextBox, and override the setText() method so that it first calls super.setText() and then does whatever event generation you'd like

Calling a Movieclip from the stage from a Class

I'm trying to call a movieclip called mcMain that's already on the stage. I'm calling it from a class and I've tried googling a whole bunch of possible solutions, none of which appear to work. I've tried stage.mcMain, this.stage.mcMain, MovieClip(root).mcMain, but nothing seems to work. Anyone got any ideas? I don't even get an error message. Just nothing happens.
I don't think that the root of your document timeline is actually the stage. However, you shouldn't be doing this. If the "Class," as you call it, is a DisplayObject, it should not know about anything outside its own scope (unless you've exposed properties or methods on it that would allow for this information to be passed in. If the Class is a data class it shouldn't know about the View at all. If it's a controller class, you'll need to pass a reference to it.
However, given the code you said you tried, I'm guessing your Class instance is some sort of DisplayObject. What you should do is dispatch a bubbling event from your Class, and then in your main Document class, listen for that event. In the event handler function, do whatever you need to do with your mcMain instance, such as adding ketchup. This should work just fine, because your main document Class can receive events from anywhere in the display list, and mcMain is its own instance.

is there a dataProviderChange event for dropdownlist?

I have a case where the SelectedItem isn't called after the data provider changes for
a dropdownlist.
is there a way to detect if such a change occurred?
Thanks
Just about every public property in the Flex Framework has a 'propertyChanged' event that is dispatched from the properties set method. They are used primarily for binding purposes, but not usually formally documented.
The dataProvider set method of a DropDownList does indeed dispatch a dataProviderChanged event. The code is several layers up in the hierarchy, as part of SkinnableDataContainer or if the skin for your 'SkinnableDataContainer' has a dataGroup it is dispatched from the DataGroup.
But, this event will probably will not be exposed via code hinting in MXML. You'll have to listen for it in ActionScript:
myList.addEventListener('dataProviderChanged', onDataProviderChanged);
Keep in mind this event will always be dispatched when the dataProvider changes, regardless of what happens to the selectedItem property.
You can listen to changes in the selectedItem in a DropDownList through the IndexChangeEvent, illustrated by the code below:
<s:DropDownList id="dl_mydl"
dataProvider="{dataProvider}"
change="dropDownListChangeHandler(event)"
/>
protected function dropDownListChangeHandler(event:IndexChangeEvent) : void
{
//DO SOMETHING
}

Actionscript 3 - Is it ok to have a bunch of code inside an event listener handler?

I'm creating a GUI, but only if things go ok, so can i
addEventListener(Event.Complete, go) to something and in the go function create my GUI (grafical elements such as labels, lists, squares)?
Is it ok to do that?
Technically it's fine. crooksy88 gives a good example of supplying a default value for the event parameter to make the function more versatile.
However, for the sake of semantics, clarity, and maintenance I would usually prefer to separate things more. So mine might be set up more like this:
protected function onLoadComplete(e:Event):void {
initAppSettings();
createUI();
startApp();
}
It makes it much easier to understand the flow of the app and what each part does just by reading the function names. When I come back to this later, I'll know that my UI is created in the function named createUI and not have to figure out that it gets created in an event handler with a cryptic name like go or handleEvent.
Also, if I want to change the flow of my app, say to pop up a dialog once the load is complete before the UI is created, I just have to move around some function calls, instead of moving around large chunks of code.
Yes that is perfectly fine. The go function isn't part of the event listener.
function go(e:Event):void {
// do something
}
The sample above requires the event parameter from the listener (e:Event).
But you can modify the function so that the parameter is optional so you can call the go function any time you want
function go(e:Event = null):void {
// do something
}
The example above will be triggered by the listener and also by typing
go();