如何在类中添加.as扩展Sprite? 我们在Flash Professional中创建了Easy1,通过FMS为2个用户创建了直播视频,现在我们想将easy1组合成HelloFlerry来调用Flash-Java本机进程。
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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="600" minHeight="400"
xmlns:flerry="net.riaspace.flerry.*"
xmlns:easy1="Easy1.*">
<easy1:Easy1 label="Easy1"/>
<easy1:Script source="Easy1.as"/>
package Easy1
{
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
public class Easy1 extends Sprite
{
private var nc:NetConnection;
private var good:Boolean;
private var rtmpNow:String;
private var nsIn:NetStream;
private var nsOut:NetStream;
private var cam:Camera;
private var mic:Microphone;
private var vidLocal:Video;
private var vidStream:Video;
public function Easy1()
{
trace("Hello testing");
rtmpNow = "rtmp://localhost/LiveStreams";
nc=new NetConnection();
nc.connect(rtmpNow);
nc.addEventListener(NetStatusEvent.NET_STATUS,checkCon);
setCam();
setMic();
setVideo();
}
private function checkCon(e:NetStatusEvent):void
{
good = e.info.code == "NetConnection.Connect.Success";
if (good)
{
nsOut = new NetStream(nc);
nsOut.attachAudio(mic);
nsOut.attachCamera(cam);
nsOut.publish("left","live");
nsIn = new NetStream(nc);
nsIn.play("right");
vidStream.attachNetStream(nsIn);
}
}
private function setCam()
{
cam = Camera.getCamera();
cam.setKeyFrameInterval(9);
cam.setMode(240,180,15);
cam.setQuality(0,80);
}
private function setMic()
{
mic = Microphone.getMicrophone();
mic.gain = 85;
mic.rate = 11;
mic.setSilenceLevel(15,2000);
}
private function setVideo()
{
vidLocal = new Video(cam.width,cam.height);
addChild(vidLocal);
vidLocal.x = 15;
vidLocal.y = 30;
vidLocal.attachCamera(cam);
vidStream = new Video(cam.width,cam.height);
addChild(vidStream);
vidStream.x=(vidLocal.x+ cam.width +10);
vidStream.y = vidLocal.y;
}
}
}
答案 0 :(得分:1)
MXML是一个模板,它可以为您有效地创建包声明,因此一旦您尝试添加自己的包声明,您将复制包定义,这是不允许的。
你也不能在&lt; Script&gt;中声明类。标签。来自&lt; Script&gt;的代码tag进入类的方法和属性定义块。
如果必须声明包和类 - 请使用* .as文件。如果您希望使用MXML模板为您声明它们 - 那么,请不要自己声明它们。你不能同时拥有两者。