(新人求教!!)flex颜色变化。。

卟惹尘埃 2011-01-10 01:56:03
<?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">


<fx:Script>


</fx:Script>

<s:states>
<s:State name="State1"/>
<s:State name="State2"/>
</s:states>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>

<!--State1-->

<s:Button x="82" y="156" width="351" height="31" chromeColor="#8283A7" focusColor="#8283A7" includeIn="State1"/>
<s:Button styleName="button" id="show1" x="82" y="156" height="31" label="首页" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show2" x="150" y="156" height="31" label="数据管理 " chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show3" x="218" y="156" height="31" label="账户管理" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:RadioButton x="335" y="156" label="灰蓝" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7"/>
<s:Button includeIn="State1" x="443" y="164" label="按钮"/>
<!--State2-->

<s:Button x="82" y="156" width="351" height="31" includeIn="State2" chromeColor="#344E3A" focusColor="#8DB897"/>
<s:Button styleName="button" id="show4" x="82" y="156" height="31" label="首页" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show5" x="150" y="156" height="31" label="数据管理 " includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show6" x="218" y="156" height="31" label="账户管理" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:RadioButton x="335" y="156" label="灰蓝" height="31" includeIn="State2" focusColor="#648B6D"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" includeIn="State2" focusColor="#648B6D"/>

</s:Application>


请问下各位大侠,现在默认显示的是State1 的样式,我怎么才能实现用 RadioButton 切换为显示State2 的样式呢?该在哪儿加东西,我是今天才开始接触FLEX的,麻烦大侠详细点,简单点,感激不尽!!
...全文
150 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlgp2171 2011-01-11
  • 打赏
  • 举报
回复
注释了的RadioButton里面includeIn表示当前状态显示
没有includeIn的会总是显示
当然visible也可以控制显示,具体可以参看API
卟惹尘埃 2011-01-11
  • 打赏
  • 举报
回复
呵呵!谢谢。。可以用 但是我是初学,还看不懂,可以简略的给我讲讲是怎么实现的吗?在state1下面RadioButton被注释掉了,但是怎么还是会出现呢?
xlgp2171 2011-01-10
  • 打赏
  • 举报
回复

<?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">
<fx:Script>
<![CDATA[
protected function radioGroup_changeHandler(event:Event):void{
// TODO Auto-generated method stub
currentState = (event.target.selectedValue == "灰蓝") ? "State1" : "State2";
}
]]>
</fx:Script>
<s:states>
<s:State name="State1"/>
<s:State name="State2"/>
</s:states>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:RadioButtonGroup id="radioGroup" change="radioGroup_changeHandler(event)" />
</fx:Declarations>
<!--State1-->

<s:Button x="82" y="156" width="351" height="31" chromeColor="#8283A7" focusColor="#8283A7" includeIn="State1"/>
<s:Button styleName="button" id="show1" x="82" y="156" height="31" label="首页" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show2" x="150" y="156" height="31" label="数据管理 " chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show3" x="218" y="156" height="31" label="账户管理" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<!-- s:RadioButton x="335" y="156" label="灰蓝" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7"/>
<s:Button includeIn="State1" x="443" y="164" label="按钮"/ -->
<!--State2-->

<s:Button x="82" y="156" width="351" height="31" includeIn="State2" chromeColor="#344E3A" focusColor="#8DB897"/>
<s:Button styleName="button" id="show4" x="82" y="156" height="31" label="首页" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show5" x="150" y="156" height="31" label="数据管理 " includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show6" x="218" y="156" height="31" label="账户管理" includeIn="State2" chromeColor="#344E3A">
</s:Button>

<s:RadioButton x="335" y="156" label="灰蓝" height="31" focusColor="#648B6D" group="{radioGroup}" selected="true" />
<s:RadioButton x="380" y="156" label="灰绿" height="31" focusColor="#648B6D" group="{radioGroup}" />
</s:Application>

这样应该可以用
当然如果只是样式改变的话 可以设置成2个Css文件
通过直接使用styleManager.loadStyleDeclarations加载
卟惹尘埃 2011-01-10
  • 打赏
  • 举报
回复
js的话很简单那 但是关键是现在公司要用flex 今天我才开始学 这周就要拿点东西出来 好纠结啊
<s:ToggleButton id="alarmTB" label="ALARM!"/>
怎么用? 我菜鸟 求写个例子
jwxkk 2011-01-10
  • 打赏
  • 举报
回复
这样的导航,用js也可以实现
如果是flex,用
<s:ToggleButton id="alarmTB" label="ALARM!"/>
最简单
卟惹尘埃 2011-01-10
  • 打赏
  • 举报
回复
哦 那就是在 state1 下面 默认的是 焦点在灰蓝 在state2下默认 焦点在灰绿 对吗?
那不用单选框呢?用按钮 就像 http://www.dh028.com/ 那个网站的风格变化一样,点击那个按钮就变化。
我加你好友了,你批准下吧!以前都是搞JS 现在公司老大要我们用FLEX 唉 刚开头好难啊。
jwxkk 2011-01-10
  • 打赏
  • 举报
回复
因为你是用的不同的状态,等于接换到了不同的组件了
所以不会选中的
如果要选中就要多加代码了,等我试下发上来
卟惹尘埃 2011-01-10
  • 打赏
  • 举报
回复

<?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">


<fx:Script>



<![CDATA[
protected function myRad_changeHandler(event:Event):void
{
// TODO Auto-generated method stub
currentState = (currentState == event.currentTarget.selectedValue) ? '' : event.currentTarget.selectedValue;
trace(event);
}
]]>

</fx:Script>

<s:states>
<s:State name="State1"/>
<s:State name="State2"/>
</s:states>
<fx:Declarations>
<s:RadioButtonGroup id="myRad" change="myRad_changeHandler(event)"/>
</fx:Declarations>

<!--State1-->

<s:Button x="82" y="156" width="351" height="31" chromeColor="#8283A7" focusColor="#8283A7" includeIn="State1"/>
<s:Button styleName="button" id="show1" x="82" y="156" height="31" label="首页" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show2" x="150" y="156" height="31" label="数据管理 " chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show3" x="218" y="156" height="31" label="账户管理" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:RadioButton x="335" y="156" label="灰蓝" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7" group="{myRad}" value="State1"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7" group="{myRad}" value="State2"/>

<!--State2-->

<s:Button x="82" y="156" width="351" height="31" includeIn="State2" chromeColor="#344E3A" focusColor="#8DB897"/>
<s:Button styleName="button" id="show4" x="82" y="156" height="31" label="首页" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show5" x="150" y="156" height="31" label="数据管理 " includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show6" x="218" y="156" height="31" label="账户管理" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:RadioButton x="335" y="156" label="灰蓝" height="31" includeIn="State2" focusColor="#648B6D" group="{myRad}" value="State2"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" includeIn="State2" focusColor="#648B6D" group="{myRad}" value="State1"/>


</s:Application>




可以用。但是单选框点过去没有焦点啊,你有没有试过,还有,那个单选框怎么样让他取焦点啊?谢谢
jwxkk 2011-01-10
  • 打赏
  • 举报
回复

<?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">


<fx:Script>



<![CDATA[
protected function myRad_changeHandler(event:Event):void
{
// TODO Auto-generated method stub
currentState = (currentState == event.currentTarget.selectedValue) ? '' : event.currentTarget.selectedValue;
trace(event);
}
]]>

</fx:Script>

<s:states>
<s:State name="State1"/>
<s:State name="State2"/>
</s:states>
<fx:Declarations>
<s:RadioButtonGroup id="myRad" change="myRad_changeHandler(event)"/>
</fx:Declarations>

<!--State1-->

<s:Button x="82" y="156" width="351" height="31" chromeColor="#8283A7" focusColor="#8283A7" includeIn="State1"/>
<s:Button styleName="button" id="show1" x="82" y="156" height="31" label="首页" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show2" x="150" y="156" height="31" label="数据管理 " chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:Button styleName="button" id="show3" x="218" y="156" height="31" label="账户管理" chromeColor="#8283A7" includeIn="State1" focusColor="#393A68">
</s:Button>
<s:RadioButton x="335" y="156" label="灰蓝" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7" group="{myRad}" value="State1"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" focusColor="#393A68" includeIn="State1" chromeColor="#8283A7" group="{myRad}" value="State2"/>
<s:Button includeIn="State1" x="443" y="164" label="按钮"/>
<!--State2-->

<s:Button x="82" y="156" width="351" height="31" includeIn="State2" chromeColor="#344E3A" focusColor="#8DB897"/>
<s:Button styleName="button" id="show4" x="82" y="156" height="31" label="首页" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show5" x="150" y="156" height="31" label="数据管理 " includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:Button styleName="button" id="show6" x="218" y="156" height="31" label="账户管理" includeIn="State2" chromeColor="#344E3A">
</s:Button>
<s:RadioButton x="335" y="156" label="灰蓝" height="31" includeIn="State2" focusColor="#648B6D" group="{myRad}" value="State1"/>
<s:RadioButton x="380" y="156" label="灰绿" height="31" includeIn="State2" focusColor="#648B6D" group="{myRad}" value="State2"/>

</s:Application>



4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧