我基本上有一节课:
public class WindowEvent extends Event
{
public static const WARNEVENT:String = "warnEvent";
public static const TASKREQEVENT:String = "taskRequestEvent";
public static const TASKANNOUNCE:String = "taskAnnounce";
public static const WINDOWCHANGE:String = "windowChange";
public static const ILLEGALPOSITION:String = "illegalPosition";
// insert brevity
}
Run Code Online (Sandbox Code Playgroud)
前四个事件工作正常,但我只是添加ILLEGALPOSITION
并尝试了这个:
// inside Window.as
private function checkDimensions():void {
if(!Window._legalBoundaryEnable)
return;
... var pass:Boolean = Window.legalBoundary.containsRect(
455 this.getBounds(stage));
456 if(!pass) {
457 this.dispatchEvent(new WindowEvent(WindowEvent.ILLEGALPOSITION,
... "Illegal Position etc."));
}
}
Run Code Online (Sandbox Code Playgroud)
所以当我点击调度方法时,Flex会向我发出这个堆栈:
TypeError: Error #1034: Type Coercion failed: cannot …
我有一个mx:TextArea,我希望它的高度与其内容高度相同.没有什么特别的 - 只是一个不可编辑的文本区域和文本.我需要一种简单可靠的方法来使控件适合并显示所有文本而不需要垂直滚动 - 就像自动调整大小一样.此外,我的控件的文本将只设置一次,不会更改,因为它不可编辑.
<mx:TextArea id="myTextArea"
editable="false"
width="100%"
verticalScrollPolicy="off" >
<mx:text>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id lorem
quis ante pulvinar auctor at eget risus. Nulla facilisi. Morbi ultricies
dignissim lorem, quis suscipit felis ullamcorper et.
</mx:text>
</mx:TextArea>
Run Code Online (Sandbox Code Playgroud)
还有一个后在这里对同一话题,但因为设置有很多更复杂,因为它包括造型和约束力是与我无关.
我正在编写一个ActionScript类来处理我的Web服务调用.当我检索结果时,我想在我的主mxml应用程序中调用setter方法.我的问题是,我不知道如何从我的actionscript类,任何想法访问我的主mxml类的actionScript部分中的方法?
我刚开始使用Linux上的Adobe Flex,并且无法获得hello world示例.
我的application.mxml文件很简单
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Panel title="My Application">
<s:Label text="Hello World" fontWeight="bold" fontSize="24"/>
</s:Panel>
</s:Application>
Run Code Online (Sandbox Code Playgroud)
我按照本指南在Linux上安装Flex(OpenSUSE 11.2),解压缩到/ opt/flex.
但是我在编译时遇到了这个错误:
/opt/flex> mxmlc -show-actionscript-warnings=true --strict=true /path/to/application.mxml
Loading configuration file /opt/flex/frameworks/flex-config.xml
/path/to/application.mxml(5): Error: Could not resolve <s:Application> to a component implementation.
xmlns:s="library://ns.adobe.com/flex/spark">
Run Code Online (Sandbox Code Playgroud)
我已经浏览了/opt/flex/frameworks/flex-config.xml并添加${flexlib}
到帖子建议的所有路径引用中.但仍然没有运气.
有任何想法吗?谢谢.
这可能是一个愚蠢的问题,如果是这样,请提前道歉.我想知道在MXML中是否等同于接口?
每当我觉得需要使用界面时,我总是最终制作动作而不是MXML文件,因为我不知道是否/如何使用.
例如,我将有一个基于vbox的组件.我有4个不同的同一个实现,所以我决定使用一个接口.但是,我没有创建单个MXML接口并实现它,而是在as3中创建了一个接口.我已经在4个不同的类中实现了这个接口.
然后,我创建了4个不同的vbox容器,每个容器都有一个脚本标记中的不同实现.
这听起来像是一种合理的方法,还是我反对这里的粮食?
编辑 - 添加示例
界面
package components.content.contents
{
public interface IContent
{
function init():void;
function doSearch():void
function setSearchTerm(term:String):void
}
}
Run Code Online (Sandbox Code Playgroud)
实施(1/4)
package components.content.contents
{
public class ClipContent extends AbstractContent implements IContent
{
public function ClipContent()
{
}
public function init():void
{
}
public function doSearch():void
{
}
public function setSearchTerm(term:String):void
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
MXML文件(1/4)
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Script>
<![CDATA[
// ClipContent Container
import components.content.contents.ClipContent;
public var content:ClipContent= new ClipContent()
public function …
Run Code Online (Sandbox Code Playgroud) 我的Flex4(AIR)项目中有以下XML,用于定义菜单界面的开头:
<mx:MenuBar x="0" y="0" width="100%" id="myMenuBar" labelField="@label" itemClick="menuChange(event)">
<mx:dataProvider>
<s:XMLListCollection>
<fx:XMLList xmlns="">
<menu label="File">
<item label="New"/>
<item label="Load"/>
<item label="Save" enabled="false"/>
</menu>
<menu label="Help">
<item label="About"/>
</menu>
</fx:XMLList>
</s:XMLListCollection>
</mx:dataProvider>
</mx:MenuBar>
Run Code Online (Sandbox Code Playgroud)
我试图找到一个语法,让我在单击"加载"加载文件后将保存按钮设置为enabled = true,但是我无法弄清楚语法,有人可以提出建议.
目前检测按钮的方式是通过Switch/Case测试MenuEvent event.item.@ label的String结果.也许这不是最好的方法?
他们似乎都用不同的语法来完成同样的事情,这就是使用两种不同技术的重点.请强调使用mxml的所有可能的好处.还有一种情况,一个比另一个更有益,为什么.
请详细说明mxml与AS3的运行时行为,如Oreilly Flex 4 Cookbook第1页中所述:
"很多新人在Flex怀疑MXML和ActionScript如何涉及到另一个MXML编译器(mxmlc),通过不同的成语解析后,将它们转换成相同的对象,所以这个:
<s:Button id="btn" label="My Button" height="100"/>
Run Code Online (Sandbox Code Playgroud)
还有这个:
var btn:Button = new Button();
btn.label = "My Button";
btn.height = 100;
Run Code Online (Sandbox Code Playgroud)
产生相同的对象.主要的区别是,虽然创建在ActionScript该对象(第二个例子)创建的按钮,没有别的,创造MXML对象添加到任何组件所包含的MXML代码的按钮.Flex框架句柄调用MXML描述的对象的构造和它要么加入到母体或将其设置作为父的属性."
我正在使用Flash Builder并创建了一个spark-application Flex项目,该项目将从本地摄像头流式传输视频.如果我使用mx.controls.VideoDisplay
; 没有问题,因为它有attachCamera(camera)
方法.但Spark的VideoDisplay
组件没有那种方法.我知道我可以在Spark应用程序中使用mx控件,但我想知道:
spark.components.VideoDisplay
和之间的真正区别是mx.controls.VideoDisplay
什么?spark.components.VideoDisplay
?谢谢.
编辑:在文档中提到:" 从Flex 4.0开始,Adobe建议您使用spark.components.VideoPlayer类作为此类的替代.(mx.controls.VideoDisplay) "
我需要的动作脚本
Loading configuration file /opt/flex/frameworks/flex-config.xml
t3.mxml(10): Error: unsupported sampling rate (24000Hz)
[Embed(source="music.mp3")]
t3.mxml(10): Error: Unable to transcode music.mp3.
[Embed(source="music.mp3")]
Run Code Online (Sandbox Code Playgroud)
代码是
<?xml version="1.0"?>
<!-- embed/EmbedSound.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import flash.media.*;
[Embed(source="sample.mp3")]
[Bindable]
public var sndCls:Class;
public var snd:Sound = new sndCls() as Sound;
public var sndChannel:SoundChannel;
public function playSound():void {
sndChannel=snd.play();
}
public function stopSound():void {
sndChannel.stop();
}
]]>
</mx:Script>
<mx:HBox>
<mx:Button label="play" click="playSound();"/>
<mx:Button label="stop" click="stopSound();"/>
</mx:HBox>
</mx:Application>
Run Code Online (Sandbox Code Playgroud) 我一直在使用{}围绕MXML中的变量,而没有真正理解它们的用途.我现在需要知道我是否应该在变量周围使用它...这是做什么的?
例: <mx:label text="{variable}"/>
mxml ×10
apache-flex ×9
flex4 ×2
actionscript ×1
e4x ×1
flash ×1
flex-spark ×1
interface ×1
menubar ×1
mxmlc ×1