原著:Macromedia
翻译:十年磨一剑
使用Director MX,你可以在你的Director影片中使用Flash MX的高级特性。包括使用Flash Communication Server MX来发送与接收视频流。一些Flash MX的特性可以在Director中只用Lingo程序就可以调用了,而另一些特性则必须要有一个Flash角色才可以调用。
使用Flash Communication Server MX来发送与接收视频流需要一个舞台上有名为视频剪辑实例的Flash演员。本文详细描述了名为“Lingo_Videochat.dir”的Director例子,它包括了所使用的Flash演员和控制该演员的Lingo程序。
例子下载
例子影片被设计为展示如何建立NetConnection object以能够与Flash Communication Server MX进行通讯,建立Camera and Microphone objects以能够访问本地计算机上的摄像头和话筒硬件,建立NetStream objects以能够发送与接收视频流。所有这些被影片Lingo程序建立的objects都是ActionScript objects。一旦它们被创建,就可以用它们原有的ActionScript方法来操作它们。
例子影片包括两个场景。第一个场景允许使用者输入他自己的名字和他想进行视频通讯的人的名字。这个场景发生在第2帧上。第二个场景了用于显示从另一通讯者处传过来的视频流的Flash精灵。这个场景发生在第4帧上。
在第一个场景,使用者输入他自己的名字和他交谈的朋友的名字。在这一场景中的“Connect”按钮被加上了名为“connect button behavior”的行为。这个行为在下面的部分会详细讨论。
在第二个场景,从另一通讯者处传过来的视频流会被显示在Flash精灵上。这个Flash精灵的Flash演员是十分简单的,它仅是舞台上有一个名为视频剪辑的实例的Flash影片。该Flash影片的SWF和FLA版都包含在本文的下载包中了。打开“simplevideo.fla”文件,你可以看到只有一个简单的名叫“VideoClip”的视频剪辑实例。这个Flash精灵被附上了名为“Flash sprite behavior”的行为。这个行为执行创建NetConnection, Microphone, Camera, and NetStream objects的主要工作。这些都是你可以用Lingo来创建和控制的Flash ActionScript objects。第二个场景也包括了一个用于结束与Flash Communication Server MX连接的“Disconnect”按钮。
“Connect”按钮的行为
“Connect”按钮上附上的行为包含以下Lingo:
global gNames
property pSprite
on beginSprite (me)
-- initialize a sprite reference
pSprite = sprite(me.spriteNum)
-- initialize the sprite's cursor
pSprite.cursor = 280
end beginSprite
on mouseDown (me)
-- pull each name entry
tPublishName = me.stripSpaces( member("publish name").text )
tSubscribeName = me.stripSpaces( member("subscribe name").text )
-- verify that names have been entered
if ((tPublishName <> "") AND (tSubscribeName <> "")) then
-- store both names in a global variable
gNames = [:]
gNames.addProp(#publishName,tPublishName)
gNames.addProp(#subscribeName,tSubscribeName)
-- jump to the next marker
go next
end if
end mouseDown
on stripSpaces (me, aString)
-- clear all spaces from the string
repeat while offset(SPACE,aString)
tCharIndex = offset(SPACE,aString)
delete aString.char[tCharIndex]
end repeat
-- return the string
return aString
end stripSpaces
这个行为包含一个变量声明、一个属性声明和三个处理程序:on beginSprite 、on MouseDown 和 on stripSpaces。
全局变量gNames被用于储存一个包含两方使用者名字的属性列表。属性变量pSprite被用于储存“Connect”按钮精灵的引用。
on beginSprite处理程序包含以下Lingo:
on beginSprite (me)
-- initialize a sprite reference
pSprite = sprite(me.spriteNum)
-- initialize the sprite's cursor
pSprite.cursor = 280
end beginSprite
它开始于以对该行为附加于其上的精灵的引用来初始化属性变量pSprite。然后该处理程序设定精灵的cursor属性的值为280,这会使鼠标指针在该精灵上时会变为手指状。
on mouseDown处理程序使用on stripSpaces处理程序来删除输入的名字前的空格,然后使用以下Lingo来把名字存入变量gNames中:
on mouseDown (me)
-- pull each name entry
tPublishName = me.stripSpaces( member("publish name").text )
tSubscribeName = me.stripSpaces( member("subscribe name").text )
-- verify that names have been entered
if ((tPublishName <> "") AND (tSubscribeName <> "")) then
-- store both names in a global variable
gNames = [:]
gNames.addProp(#publishName,tPublishName)
gNames.addProp(#subscribeName,tSubscribeName)
-- jump to the next marker
go next
