flex 如何取得光标在TextInput的text里的位置?还有怎么设置光标在TextInput的text里的位置
我要搞一个触摸屏用的功能,但是一点击按钮,输入框光标就不见了,如何做到光标一直都在TextInput里?...
我要搞一个触摸屏用的功能,但是一点击按钮,输入框光标就不见了,如何做到光标一直都在 TextInput里?
展开
展开全部
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="init(event)" xmlns:controls="com.boco.mds2.controls.*" xmlns:login="com.boco.mds2.modules.login.*">
<fx:Script>
<![CDATA[
import com.as3xls.xls.ExcelFile;
import com.as3xls.xls.Sheet;
import com.boco.mds2.modules.colony.NewStation;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.MenuEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var obj:ArrayCollection;
private var roleId:Object = 1;
private var modArr:ArrayCollection = new ArrayCollection();
protected function init(event:FlexEvent):void
{
roleService.selectModuleByUser(roleId)
focusManager.setFocus(ti);
}
private function loadPageModuleByRoleResult(event:ResultEvent):void
{
modArr = event.result as ArrayCollection;
//var companyData:ArrayCollection = new ArrayCollection([{modName:"功能模块选哪运汪择",modId:"李仔001",children:new ArrayCollection([modArr])}])
//tree.dataProvider = modArr;
}
protected function bt_clickHandler(event:MouseEvent):void
{
//Alert.show(df1.df.selectedDate.toLocaleDateString()+"-||-"+df1.df.selectedDate.toLocaleDateString())
ti.setFocus();
}
protected function logPageService_faultHandler(event:FaultEvent):void
{
}
protected function loadModule(event:MenuEvent):void {
}
private function exportExecl():FileReference{
var _sheet:Sheet = new Sheet(); //Excel选项卡
var _fields:Array = []; //需要呈现的字段数组
var filename:String = "";
var columns:Array = new Array;
var rows:ArrayCollection = new ArrayCollection;
//if(grid.visible == true){
columns=pag.grid.columns as Array;//获得头部数据
rows=pag.grid.dataProvider as ArrayCollection;//获得数据
filename = pub.label;
//}
var colCount:int = columns.length;//获得头部长度悄笑
var rowCount:int = rows.length;//获得数据长度
_sheet.resize(rowCount+3 , colCount); //设置当前选项卡 有多少行多少列
_sheet.header = pub.label;
for(var i:uint = 0; i<colCount; i++){
var col:String = columns[i].headerText.toString();
_sheet.setCell(0, i, col); //设置单元格 参数:1、行号;2、列号;3、单元格的值
_fields.push(columns[i].dataField.toString()); //保存字段
}
// 生成数据
for (i = 0; i<rowCount; i++) {
var row:Object = rows[i];
for(var j:uint = 0; j<_fields.length; j++){
var field:String = _fields[j];
var val:String = "";
if(row[field]){
val = row[field].toString();
}
_sheet.setCell(i+1, j, val); //设置单元格 参数:1、行号;2、列号;3、单元格的值
}
}
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(_sheet); //把选项卡写入Excel文件中
var bytes:ByteArray = xls.saveToByteArray();
var fr:FileReference = new FileReference(); //保存对话框
fr.save(bytes, filename + ".xls");
return fr;
}
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject id="roleService" destination="roleService" fault="logPageService_faultHandler(event)">
<s:method name="selectModuleByUser" result="loadPageModuleByRoleResult(event)"/>
</s:RemoteObject>
</fx:Declarations>
<mx:Canvas width="100%" height="100%">
<s:Panel title="全局日志管理" top="30" width="100%" height="100%" fontSize="14" fontFamily='Microsoft YaHei'>
<s:HGroup top="5" left="10" height="50" verticalAlign="middle">
<s:Label id='lb' text="模块选择 :" fontSize="14" fontFamily='Microsoft YaHei' verticalCenter="0"/>
<mx:ApplicationControlBar dock="true" >
<mx:PopUpButton id="pub" label="{tree.selectedItem.modName}" >
<mx:popUp>
<mx:Tree id="tree" textAlign="left" fontFamily="Microsoft YaHei"
labelField="modName" paddingRight="10"
width="350"
rowCount="8" />
</mx:popUp>
</mx:PopUpButton>
</mx:ApplicationControlBar>
<s:Label id='lbStart' text="开始时间" fontSize="14" fontFamily='Microsoft YaHei' verticalCenter="0" />
<controls:DateTimeField id="df1" verticalCenter="0" />
<s:Label id='lbEnd' text="结束时间" fontSize="14" fontFamily='Microsoft YaHei' verticalCenter="0"/>
<controls:DateTimeField id="df2" verticalCenter="0"/>
<s:Button id="bt" label="确定" click="bt_clickHandler(event)" fontSize="14" fontFamily='Microsoft YaHei'/>
<s:TextInput id="ti" />
</s:HGroup>
<s:Image source="assets/mds2/kpichart/excel.png" toolTip="导出EXECL" right="10" top="30"
buttonMode="true" id="imageExecl" height="25" width="25" click="exportExecl()"/>
<login:paging id='pag' top='56' bottom="10" left="10" right="10"/>
</s:Panel>
</mx:Canvas>
</s:Application>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="init(event)" xmlns:controls="com.boco.mds2.controls.*" xmlns:login="com.boco.mds2.modules.login.*">
<fx:Script>
<![CDATA[
import com.as3xls.xls.ExcelFile;
import com.as3xls.xls.Sheet;
import com.boco.mds2.modules.colony.NewStation;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.MenuEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var obj:ArrayCollection;
private var roleId:Object = 1;
private var modArr:ArrayCollection = new ArrayCollection();
protected function init(event:FlexEvent):void
{
roleService.selectModuleByUser(roleId)
focusManager.setFocus(ti);
}
private function loadPageModuleByRoleResult(event:ResultEvent):void
{
modArr = event.result as ArrayCollection;
//var companyData:ArrayCollection = new ArrayCollection([{modName:"功能模块选哪运汪择",modId:"李仔001",children:new ArrayCollection([modArr])}])
//tree.dataProvider = modArr;
}
protected function bt_clickHandler(event:MouseEvent):void
{
//Alert.show(df1.df.selectedDate.toLocaleDateString()+"-||-"+df1.df.selectedDate.toLocaleDateString())
ti.setFocus();
}
protected function logPageService_faultHandler(event:FaultEvent):void
{
}
protected function loadModule(event:MenuEvent):void {
}
private function exportExecl():FileReference{
var _sheet:Sheet = new Sheet(); //Excel选项卡
var _fields:Array = []; //需要呈现的字段数组
var filename:String = "";
var columns:Array = new Array;
var rows:ArrayCollection = new ArrayCollection;
//if(grid.visible == true){
columns=pag.grid.columns as Array;//获得头部数据
rows=pag.grid.dataProvider as ArrayCollection;//获得数据
filename = pub.label;
//}
var colCount:int = columns.length;//获得头部长度悄笑
var rowCount:int = rows.length;//获得数据长度
_sheet.resize(rowCount+3 , colCount); //设置当前选项卡 有多少行多少列
_sheet.header = pub.label;
for(var i:uint = 0; i<colCount; i++){
var col:String = columns[i].headerText.toString();
_sheet.setCell(0, i, col); //设置单元格 参数:1、行号;2、列号;3、单元格的值
_fields.push(columns[i].dataField.toString()); //保存字段
}
// 生成数据
for (i = 0; i<rowCount; i++) {
var row:Object = rows[i];
for(var j:uint = 0; j<_fields.length; j++){
var field:String = _fields[j];
var val:String = "";
if(row[field]){
val = row[field].toString();
}
_sheet.setCell(i+1, j, val); //设置单元格 参数:1、行号;2、列号;3、单元格的值
}
}
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(_sheet); //把选项卡写入Excel文件中
var bytes:ByteArray = xls.saveToByteArray();
var fr:FileReference = new FileReference(); //保存对话框
fr.save(bytes, filename + ".xls");
return fr;
}
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject id="roleService" destination="roleService" fault="logPageService_faultHandler(event)">
<s:method name="selectModuleByUser" result="loadPageModuleByRoleResult(event)"/>
</s:RemoteObject>
</fx:Declarations>
<mx:Canvas width="100%" height="100%">
<s:Panel title="全局日志管理" top="30" width="100%" height="100%" fontSize="14" fontFamily='Microsoft YaHei'>
<s:HGroup top="5" left="10" height="50" verticalAlign="middle">
<s:Label id='lb' text="模块选择 :" fontSize="14" fontFamily='Microsoft YaHei' verticalCenter="0"/>
<mx:ApplicationControlBar dock="true" >
<mx:PopUpButton id="pub" label="{tree.selectedItem.modName}" >
<mx:popUp>
<mx:Tree id="tree" textAlign="left" fontFamily="Microsoft YaHei"
labelField="modName" paddingRight="10"
width="350"
rowCount="8" />
</mx:popUp>
</mx:PopUpButton>
</mx:ApplicationControlBar>
<s:Label id='lbStart' text="开始时间" fontSize="14" fontFamily='Microsoft YaHei' verticalCenter="0" />
<controls:DateTimeField id="df1" verticalCenter="0" />
<s:Label id='lbEnd' text="结束时间" fontSize="14" fontFamily='Microsoft YaHei' verticalCenter="0"/>
<controls:DateTimeField id="df2" verticalCenter="0"/>
<s:Button id="bt" label="确定" click="bt_clickHandler(event)" fontSize="14" fontFamily='Microsoft YaHei'/>
<s:TextInput id="ti" />
</s:HGroup>
<s:Image source="assets/mds2/kpichart/excel.png" toolTip="导出EXECL" right="10" top="30"
buttonMode="true" id="imageExecl" height="25" width="25" click="exportExecl()"/>
<login:paging id='pag' top='56' bottom="10" left="10" right="10"/>
</s:Panel>
</mx:Canvas>
</s:Application>
追问
你的代码在我这不能运行啊,有些包我这没
追答
注释掉就好了啊!
展开全部
用focusManager.setFocus不可以吗,点击按钮的时候强制携兆将光标厅隐弊focus到输入扮族框……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
真没注意过这个东西,试试focus,点完按钮设置一下focus在textinput里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询