I want to design a calculator by Flash cs5 , I use appendText Method to write the data in the textfield by the Keyboard . My problem is when I start the application I have to Click on the TextField first then type the numbers . How i can solve it .
Cheers,
Maged
What type of TextField are you using?!
Provided that you have created a dynamic TextField with the instance name of textfield, the following should work.
textfield.restrict = "0-9";
textfield.text = "";
function onKeyBoardEvent( event:KeyboardEvent ):void
{
var str:String = String.fromCharCode(event.charCode );
textfield.appendText( str);
}
you can set focus to the text field as soon as it's added to stage.
frame script:
stage.focus = textFieldInstance;
package:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class DocumentClass extends Sprite
{
public function DocumentClass()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.focus = textFieldInstance;
}
}
}
Related
I have a class FlexNativeWindow who extends to NativeWindow.
I use this method to create new window on my AIR app.
All works well but some keyboard interraction is not availaible.
For exemple focus arround textinput is not visible.
Key down and up don't work on DropDownList.
TabOrder doesn't work well!
Can you explain Why? Because I'm very desapointed!
Code to create the new window
var wdetcorr:wDetailCorrespondant = new wDetailCorrespondant();
wdetcorr.monIdCorresp = correspDG.selectedItem.crIndex;
var wOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
wOptions.systemChrome = NativeWindowSystemChrome.NONE;
wOptions.transparent = false;
var fnwDetailPatient:FlexNativeWindow = new FlexNativeWindow(wdetcorr, wOptions);
fnwDetailPatient.active();
Code about my custom NativeWindow
package fr.int.ui.windowSkin
{
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import mx.core.IUIComponent;
import mx.core.IVisualElement;
import mx.core.IVisualElementContainer;
import mx.core.UIComponent;
import mx.events.*;
import mx.managers.WindowedSystemManager;
[Event(name="creationComplete", type="mx.events.FlexEvent")]
public class FlexNativeWindow extends NativeWindow implements IFlexNativeWindow
{
private var _systemManager:WindowedSystemManager;
private var _content:UIComponent;
private var _window:IVisualElementContainer;
public function FlexNativeWindow(window:IVisualElementContainer, initOptions:NativeWindowInitOptions = null)
{
super(initOptions);
_window = window;
addEventListener(Event.ACTIVATE, windowActivateHandler);
}
public function addElement(control:IVisualElement):void
{
_window.addElement(control);
}
public function removeElement(control:IVisualElement):void
{
_window.removeElement(control);
}
private function windowActivateHandler(event:Event):void
{
event.preventDefault();
event.stopImmediatePropagation();
removeEventListener(Event.ACTIVATE, windowActivateHandler);
if (stage)
{
if (!_systemManager)
_systemManager = new WindowedSystemManager(IUIComponent(_window));
stage.addChild(_systemManager);
dispatchEvent(new FlexEvent(FlexEvent.CREATION_COMPLETE));
stage.addEventListener(Event.RESIZE, windowResizeHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
}
}
private function keyDownListener (e:KeyboardEvent):void {
if (e.keyCode == Keyboard.ESCAPE) {
stage.nativeWindow.dispatchEvent(new Event("myEventClose", true));
stage.nativeWindow.close();
}
}
private function windowResizeHandler(event:Event):void
{
// prise en compte de la valeur mini
UIComponent(_window).height = stage.stageHeight;
UIComponent(_window).width = stage.stageWidth;
}
}
}
You should implement IFocusManagerContainer in FlexNativeWindow to fix the focus issues.
Here is how to do it in Flash Builder:
Press Ctrl + Shift + T and type in IFocusManagerContainer
Open corresponding file
Implement all declared methods in your class FlexNativeWindow
P.S: However this approach can fail because flex components should be placed inside flex container while NativeWindow is a native class, not a Flex SDK class. I suggest you to use Window class that is a Flex container and already implements IFocusManagerContainer.
I have a button which I use for sending a message. When the message text is empty, it should not be possible to click the button.
This is all fine and not an issue. The only thing that is bugging me is the fact that I can disable the send button but the image does not get disabled (like I would expect).
Is there a way to do this elegantly because I don't want to provide a sendicon_disabled.png and change it myself (I don't think this should be my job).
You can use the following button for that:
package
{
import mx.controls.Button;
import mx.core.mx_internal;
use namespace mx_internal;
public class IconButton extends Button
{
private var enabledChanged:Boolean = false;
override public function set enabled(value:Boolean):void
{
if (super.enabled == value)
{
return;
}
super.enabled = value;
enabledChanged = true;
invalidateDisplayList();
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (enabledChanged)
{
if (!enabled && currentIcon)
{
currentIcon.alpha = 0.5;
}
enabledChanged = false;
}
}
}
}
You can use your custom alpha value or move it to separate style.
Is there any workaround to create submenu in a flex context menu other than stopping right click from javascript.
Regards,
Hi Frank,
Yes, I want to create submenus in a context menu. Can you help me here.
Regards,
Hi Frank,
I need the context menu for the application not for datagrid.
In my initial question the phrase "other than stopping right click from javascript" means
"catch the right click in html, call a javascript function and over js call a as function."
The project that you have specified does the above procedure. I don't want to use this
procedure. Is there any other way for achieving submenus in a flex context menu. Could you
please tell me if so..
Regards,
Arvind
Yes, there is.
I don't know, what you exactly mean with this:
other than stopping right click from
javascript.
But, if you want to create a entry in submenu, do this:
//Instance of my own class
private var myContext:myContextMenu = new myContextMenu();
application.contextMenu = myContext.myContextMenu;
//Here is the Class:
package com.my.components
{
/* ////////////////////////////////////////////
///// My Context MenĂ¼ /////////////////////
///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//to use: //
// private var myContext:MyContextMenu = new MyContextMenu(); //
// init() in creationComplete //
// application.contextMenu = myContext.myContextMenu; //
////////////////////////////////////////////////////////////////////////////// */
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextField;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuBuiltInItems;
import flash.ui.ContextMenuItem;
public class MyContextMenu extends Sprite
{
public var myContextMenu:ContextMenu;
private var menuLabel:String = String.fromCharCode(169)+" My Company GmbH";
public function MyContextMenu()
{
myContextMenu = new ContextMenu;
removeDefaultItems();
addCustomItems();
myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);
super();
}
private function removeDefaultItems():void
{
myContextMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
defaultItems.print = true;
}
private function addCustomItems():void
{
var item:ContextMenuItem = new ContextMenuItem(menuLabel);
myContextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelectHandler);
}
private function menuSelectHandler(event:ContextMenuEvent):void
{
}
private function menuItemSelectHandler(event:ContextMenuEvent):void
{
navigateToURL(new URLRequest('http://www.my-company.de'));
}
private function createLabel():TextField
{
var txtField:TextField = new TextField();
//txtField.text = textLabel;
txtField.text = "RightClickHere";
return txtField;
}
}
}
Have fun
EDIT:
There is an interesting project here. They catch the right click in html, call a javascript function and over js call a as function.
Unfortunately, the limitation of FP or NativeMenu APi allowed just on level contextmenu. Read here
Frank
I was wondering if anyone had any luck with the following senario in flex.
I'd like to be able to have a custom item renderer which delegates to another renderer inside.
The reason for this would be in a datagrid for instance displaying a checkbox if the dataprovider for the row had a boolean value. Using the default item renderer when the value was a non boolean.
Basically I was hoping to use a proxy object (though not necessarily the proxy class) so that I could a renderer which delegated all of its responsibilties to a sub renderer.
Hard to explain.
Edit 1
I think the following gives a clearer idea of what I had in mind. This is only knocked up quickly for the purpose of showing the idea.
SwitchingRenderer.as
package com.example
{
import mx.controls.CheckBox;
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.core.IDataRenderer;
import mx.core.UIComponent;
public class SwitchingRenderer extends UIComponent implements IDataRenderer, IDropInListItemRenderer
{
private var checkboxRenderer:CheckBox;
private var defaultRenderer:DataGridItemRenderer;
private var currentRenderer:IDataRenderer;
public function SwitchingRenderer()
{
this.checkboxRenderer = new CheckBox();
this.defaultRenderer = new DataGridItemRenderer();
this.currentRenderer = defaultRenderer();
super();
}
public function get data():Object
{
//If the data for this cell is a boolean
// currentRender = checkBoxRenderer
// otherwise
// currentRenderer = defaultRenderer
}
public function set data(value:Object):void
{
currentRenderer.data = value;
}
public function get listData():BaseListData
{
return currentRenderer.listData;
}
public function set listData(value:BaseListData):void
{
currentRenderer.listData = value;
}
}
}
If you're using Flex 4 spark components look into the itemRendererFunction,
Here is a good sample from the interwebs.
Unfortunately, Flex 3 components, such as the DataGrid do not support that.
You're a bit vague on what you'd be displaying if the data sent into the itemRenderer was not a Boolean value. But, you can easily modify the visual appearance of a component based on the data change event, including swapping visible properties of a component's children, changing states or change the selectedIndex of a ViewStack. All these things can be done within an itemRenderer w/o issues.
Edit:
Based on the user's additional posting, I'd add that what he is after can be done like this:
public function get data():Object
{
if(this.data is Boolean){
checkBoxRenderer.visible = true;
defaultRenderer.visible = false;
} else {
checkBoxRenderer.visible = false;
defaultRenderer.visible = true;
}
}
When I debug my code nothing appears on screen. I've rechecked the code and consulted with others yet nothing appears. My html template is fine.
package {
import flash.display.Sprite;
import flash.events.*;
public class asgnv2 extends Sprite
{
var lineY = 0;
public function asgnv2()
{
stage.addEventListener(Event.ENTER_FRAME, update);
graphics.lineStyle(1);
}
function update(e){
graphics.clear();
graphics.moveTo(0 ,lineY);
graphics.lineTo(100, lineY);
lineY+=0.5;
}
}
}
unless asgnv2 is Document class, it is not going to work, as you are registering ENTER_FRAME event on the stage inside the constructor of asgnv2. A DisplayObject can not access stage property until it is added to Stage Display List. So try the following. public function asgnv2(){
this.addEventListener(Event.ADDED_TO_STAGE, onAdded);
graphics.lineStyle(1);
}
private function onAdded(e:Event):void {
stage.addEventListener(Event.ENTER_FRAME, update);
this.removeEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function update(e:Event):void{
//do the stuff
}