setting the default button in preinitialization - apache-flex

I have a more than one container in a view. I am trying to set default button at the moment page is loaded so that when I press enter, function that handles keydown event called. If I simply set default button in preinit() function, it does not work.
How can I do this ?

It's tough to debug "Does not work" sometimes. But, in this case I suspect you get a "Null value" style error.
The preinitialize event is fired before createChildren() so most likely the button you want make the "Default" doesn't exist yet. More info about the Flex Component LifeCycle.
You can move your code to the initialize event.
I assume that by "setting the default" you mean you are using the FocusManager to give your button focus?

Assuming I understand your question correctly, you need to do two things to make this work.
Set the defaultButton
Set focus to the container or some child of the container
As #Flextras said, preinit may also not be the best choice for this.
If the container is declared in MXML, I recommend setting the defaultButton property in the MXML declaration, and setting focus on creationComplete.

Related

NavigatorContent onSelect

Is there any shortcut way to add an eventListener to something like a select event for NavigatorContent.
I am aware I can add a listener for a change event on the ViewStack and identify the selected NavigatorContent through that handler.
The ViewStack component dispatch a CREATION_COMPLETE event on the new selectedChild
As2 has shortcuts for what you want, im afraid as3 doesnt as AS3 wants to know exactly whats needed to care for at what time.
an update /enterframe function can reduce some code but apply more load on the swf over all as its waitng for a call.
throw some code up in your question so we all know exactly what your talking about.

Flex 3 TileList selected item strange behaviour

I have a Flex TileList with an itemRenderer made by me.
The list loads the content perfectly and renders it.
Renderer is a simple canvas element with a checkbox and another canvas with some labels with data.
I implemented a method that, on TileList itemClick="clickedItemHandler(event)", changes the state of the checkbox (if checked -> uncheck, and vice versa).
Problem is: the method works if i click on any place of the item, EXCEPT the checkbox. When i click the checkbox, it doesn't change state.
My thoughts: maybe i was changing the state of the checkbox, and the event changing it back, but i debugged it and it doesn't look like so..
The solution is actually quite simple. Perhaps the best way to make this work is making sure the CheckBox ignores mouse clicks, and this can be done by setting the "mouseEnabled" attribute to false.
Cheers
I think you're probably correct. The checkbox toggles when you click it and then you toggle it back when the event gets to the TileList. You may not see this when debugging depending on how you are confirming... you may be able to fix this by confirming that the target of the event is not a CheckBox.

Flex 4: How to override the default button functionality in a skin class?

I have a videoplayer with a custom skin class. I want to override the functionality of the fullscreen button. When I add an click event, the player still goes into fullscreen mode. How can I prevent the fullscreen event from firing?
It turns out that if you change the id of the button to anything other than the default then you regain full control over the button.
I changed fullScreenButton to customFullScreenButton (below):
<s:Button id="customFullScreenButton" label="Fullscreen"
click="handleFullscreenButtonClicked(event);"
skinClass="FullScreenButtonSkin"/>
Have you tried calling stopImmediatePropagation on the event when your event listener gets called? That should stop it from bubbling, but I'm not sure if your listener will get it first. It's worth a shot though. Hope that helps.

ActionScript-3 calling addEventListener more than once

I've a little problem, I don't really understand if I can use addEventListener more than one time on the same object (and same callback function) if this case can I have a problem of overflow, or simple flex is so smart to not add again in the same stack same function
for examples:
var t:CServiceObj = _rModel.userGetBoardJoined();
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
As you say, Flex is "smart" and even if you subscribe to an event more than once on the same instance, then the handler will be called Just once (no matter how many addEventListener you pass).
I tried a quick test on Button and it doesn't matter if the addEventListener is added multiple times to the same function -- it gets dispatched once.
However, you could set up something like this
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk2);
where onDataOk2 calls onDataOk with the event parameter.
Interesting Note
A different test, I added a click handler in the mxml tag, and a click handler in the AS, both pointed to the same function. When the button was clicked, both handlers dispatched, so Flex did something behind the scenes to accomodate this functionality.

how can I write a generic property modification function in Flex/Actionscript3?

I'm new to Flex, although not new to programming. I want to write a generic event handler that will be called by all my textinput boxes when they receive focus. When they have focus, I want to change the colour of the textinput box. When they lose focus, I want to restore the "inactive" color profile. I could write an ActionScript event handler for each textinput box, but we all know that's lame. :o) What I need, then, is a way to access the object which is calling the event handler.
In Delphi, I'd have written a function which passes in the Sender object, allowing me to access the calling object's properties. I'm guessing ActionScript/Flex has a completely different architecture, which is why I'm having difficulty doing this.
Thanks in anticipation!
You should subclass TextInput and handle the focus events in there. I think this would be the simplest way to achieve what you are looking for without having any complex code.
I hope I'm understanding what you're asking for... are you talking about event delegation?
This worked for me:
// 'focusOut' for blur
stage.addEventListener('focusIn', function(e:Event):void {
// The focused control is e.target
});
If you want to change the look of the focused input box, you can do this by setting the focusSkin property. If you want this to happen globally, you can put a style declaration in your CSS file.
In this CSS example I'm replacing the default focusSkin (mx.skins.halo.HaloFocusRect) with an embedded PNG file.
TextInput {
focusSkin: Embed(source="focus.png");
}
TextInput has a few properties for altering the look of the focus, like changing the opacity of the focus skin (focusAlpha property). Check the TextInput documentation for more info.

Resources