I installed red5 successfully, but when I try to connect to red5 to stream a video, the connection fails. If I use netstreaming(null), it works, but when I use red5, it doesn't.
I use following code to connect the stream:
<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();">
<fx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
private var nc:NetConnection;
private var ns:NetStream;
private var video:Video;
private var meta:Object;
private var videoURL:String = "Fleximagteaser.flv";
private var nc1:NetConnection;
private var ns1:NetStream;
private var video1:Video;
private var meta1:Object;
private function init():void {
//video1
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
nc = new NetConnection();
nc.connect("rtmp://localhost/demo");
ns = new NetStream(nc);
ns.play(videoURL);
ns.client = nsClient;
video = new Video();
video.attachNetStream(ns);
uic.addChild(video);
}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.
video.width = item.width;
video.height = item.height;
// Resize UIComponent to same size as Video object.
uic.width = video.width;
uic.height = video.height;
panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VBox>
<mx:Panel id="panel" visible="false">
<mx:UIComponent id="uic" />
<mx:ControlBar>
<mx:Button label="Play/Pause" click="ns.togglePause();" />
<mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>
</mx:Panel>
</mx:VBox>
</s:Application>
Can anyone help?
<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();">
<fx:Script>
<![CDATA[
import flash.globalization.Collator;
import mx.utils.ObjectUtil;
private var nc:NetConnection;
private var ns:NetStream;
private var video:Video;
private var meta:Object;
private var videoURL:String = "Fleximagteaser.flv";
private var nc1:NetConnection;
private var ns1:NetStream;
private var video1:Video;
private var meta1:Object;
private function init():void {
//video1
nc = new NetConnection();
nc.connect("rtmp");
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS,onConnectionStatus);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,onErrorHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
}
private function onConnectionStatus(event:NetStatusEvent):void
{
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
ns = new NetStream(nc);
ns.play("videourl");
ns.client = nsClient;
video = new Video();
video.attachNetStream(ns);
uic.addChild(video);
}
private function onErrorHandler(event:AsyncErrorEvent):void{}
private function onSecurityError(event:SecurityErrorEvent):void{}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.
video.width = item.width;
video.height = item.height;
// Resize UIComponent to same size as Video object.
uic.width = video.width;
uic.height = video.height;
panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
public function onBWDone():void
{}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VBox>
<mx:Panel id="panel" visible="false">
<mx:UIComponent id="uic" />
<mx:ControlBar>
<mx:Button label="Play/Pause" click="ns.togglePause();" />
<mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>
</mx:Panel>
</mx:VBox>
Related
The code below imports and controls an mp3 sound file. When I change from an mp3 to an m4a file the code does not work. Do I need to use a different class to play an m4a file?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="init()" >
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
import mx.rpc.events.ResultEvent;
private var sound:Sound;
private var soundChannel:SoundChannel = new SoundChannel;
private var loaderContext:SoundLoaderContext;
private var trackPosition:Number = 0;
private var timer:Timer;
private var leftGraphic:Sprite;
private var rightGraphic:Sprite;
private function init():void{
var audioFile:String = "recording.mp3";
sound = new Sound(new URLRequest(audioFile));
sound.addEventListener(Event.COMPLETE, onSoundLoaded);
function onSoundLoaded(event:Event):void{
maxTime.text = convertMillesecs(sound.length)
trackSlider.y-= 5;
trackSlider.maximum = sound.length;
}
}
private var counter:Number
private function soundComplete( e:Event ):void{
maxTime.text = convertMillesecs(soundChannel.position);
maxTime.text = convertMillesecs(sound.length)
}
private function checkTrack(event:Event):void{
// manage track counter
trackSlider.value = soundChannel.position;
currentVal.text = String(convertMillesecs(soundChannel.position));
}
private function convertMillesecs(time:Number):String{
var h:Number = new Number(Math.floor(time/1000/60/60));
var m:Number = new Number(Math.floor(time/1000/60)-(h*60));
var s:Number = new Number(Math.floor(time/1000)-(m*60));
var hours:String;
var minutes:String;
var seconds:String
//minutes and seconds always two digits
if(m.toString().length == 1) {
minutes = "0"+m;
} else {
minutes = m.toString();
}
if(s.toString().length == 1) {
seconds = "0"+s;
} else {
seconds = s.toString();
}
// last two digits represent actual seconds
seconds = seconds.slice(seconds.length-2, seconds.length);
return minutes + ":" + seconds;
}
private function controlChange1(event:MouseEvent):void{
var optionString:String;
switch(event.target.id){
case "playButton":
play();
break;
case "pauseButton":
pause();
break;
default:
break;
}
}
private function play():void{
playButton.visible = false;
pauseButton.visible = true;
timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, checkTrack);
soundChannel.stop();
soundChannel = sound.play(pausePosition);
timer.start();
}
private var pausePosition:int
private function pause():void{
pausePosition = soundChannel.position;
soundChannel.stop();
playButton.visible = true;
pauseButton.visible = false;
}
private function onTrackSliderChange(e:Event):void{
soundChannel.stop()
soundChannel = sound.play(e.target.value * sound.length / trackSlider.maximum);
playButton.visible = false;
pauseButton.visible = true;
}
private function formatButton(val:String):String{
return convertMillesecs(soundChannel.position)
}
]]>
</mx:Script>
<mx:HBox backgroundColor="0x000000" horizontalCenter="0" verticalCenter="0" verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
<mx:Canvas id="controlBar1" paddingLeft="1" buttonMode="true" useHandCursor="true" >
<mx:Button id="pauseButton" width="40" height="40" click="controlChange1(event)" visible="false" color="0x0B333C"/>
<mx:Button id="playButton" width="40" height="40" click="controlChange1(event)" color="0x000000" />
</mx:Canvas>
<mx:Label id="currentVal" text="00:00" color="0xffffff"/>
<mx:HSlider id="trackSlider" height="10" width="500" liveDragging="false" change="onTrackSliderChange(event);"
dataTipFormatFunction="formatButton" showTrackHighlight = "true" mouseEnabled="true" useHandCursor="true" />
<mx:Label id="maxTime" text="00:00" color="0xffffff"/>
</mx:HBox>
</mx:Application>
The Sound class can play one of two formats: mp3 and the raw format AS3 records to. So it is impossible to use the Sound class to play m4a, unfortunately.
Fortunately, it is possible to play m4a using another class: NetStream. You may or may not have as fine of control over it without the SoundTransform and SoundMixer classes, but you can still play the file no problem (I've done it in the past, though it didn't end up working quite the way I was hoping for so I ended up going with mp3s instead)
Adobe Article on m4a playback
Hi I am trying to add an image when I click on a thumbnail.
I know I have to use a listener (Event.COMPLETE ?), but the image is not resizing correctly when I rotate the tablet.
I believe the problem is that I cannot resize the image within the addImage1() function, as the image has not yet loaded, but I cannot use newImg.width within the listener function to reset the image width.
Any help would be most appreciated.
Code follows:-)
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="ZOOM Pictues with Tap"
resize="view1_resizeHandler(event)">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
public var hasImageBeenAdded:Boolean = false;
private var imageLastWidth:Number;
private var imageLastHeight:Number;
private var zoomFactor:Number;
private var imageNumber:Number;
private var rhsKeepWidth:int;
private var rhsKeepHeight:int;
private var rhsKeep:Boolean = false;
protected function view1_resizeHandler(event:ResizeEvent):void
{
if(rhsKeepWidth > rhsKeepHeight) // Was Landscape is now Portrait
{
var tmpWidth2:int = rhsKeepWidth;
var tmpHeight2:int = rhsKeepHeight;
rhsKeepWidth = tmpHeight2-lhs.width;
rhsKeepHeight = tmpWidth2+lhs.width;
}
else //Was Portrait is now Landscape
{
var tmpWidth1:int = rhsKeepWidth;
var tmpHeight1:int = rhsKeepHeight;
rhsKeepWidth = tmpHeight1-lhs.width;
rhsKeepHeight = tmpWidth1+lhs.width;
}
addImage1();
}
protected function removeAllImages():void
{
var totalElements : int = rhs.numElements;
for(var i:int=totalElements-1;i>=0;i--)
{
rhs.removeElementAt(i);
}
}
private function onImageLoaded(e:Event):void
{
var zoomFactor1:Number;
var zoomFactor2:Number;
imageLastWidth = e.target.sourceWidth;
imageLastHeight = e.target.sourceHeight;
if(rhsKeep != true) //Need to set the rhs VGroup dimensions
{
rhs.width = hGroup1.width-lhs.width;
rhs.height = hGroup1.height;
rhsKeep = true;
rhsKeepWidth = rhs.width;
rhsKeepHeight = rhs.height;
}
zoomFactor1 = rhsKeepWidth/imageLastWidth;
zoomFactor2 = rhsKeepHeight/imageLastHeight;
if(zoomFactor1 < zoomFactor2)
{
zoomFactor = zoomFactor1;
}
else
{
zoomFactor = zoomFactor2;
}
trace("zoomFactor=" + zoomFactor);
}
public function addImage1():void
{
var i:int;
var newImg:Image = new Image();
removeAllImages();
newImg.source = "images/1.jpg";
newImg.x = 0;
newImg.y = 0;
newImg.addEventListener(Event.COMPLETE,onImageLoaded);
rhs.addElementAt(newImg,0);
hasImageBeenAdded = true;
imageNumber = 1;
trace("Image Width= " + newImg.width);
newImg.scaleX = newImg.scaleY = zoomFactor;
}
]]>
</fx:Script>
<s:HGroup id="hGroup1" width="100%" height="100%">
<s:Scroller id="scrollerL" height="100%">
<s:VGroup id="lhs" width="15%" height="100%" gap="10"
horizontalAlign="center" verticalAlign="top">
<s:Image width="100" height="100" source="thumbs/1.jpg" click="addImage1()"/>
</s:VGroup>
</s:Scroller>
<s:Scroller id="scroller1" height="100%" width="100%">
<s:VGroup id="rhs" height="100%">
</s:VGroup>
</s:Scroller>
</s:HGroup>
</s:View>
Regarding the device orientation, you should use:
trace(Stage.deviceOrientation);
trace(Stage.orientation);
They are read-only strings outputting information regarding the device's and the screen's orientation. You may manually set the stage's orientation:
Stage.setOrientation(StageOrientation.DEFAULT);
Regarding the image loading, you need an eventListener for Event.COMPLETE and you should also cast the content as Image:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void {
trace("Image loaded");
// Handle code here
// Use: (loader.content as Image)
});
loader.load(new URLRequest("images/1.jpg"));
I am trying to place 5 cards overlapping 30% on one another. and trying to give a movement to it using mouse events . It should drop within the 5 cards only, not outside of that.
I have learned the drag and drop events and executed it, but i cannot place the card within the 5 cards .
Please somebody help me in this. Please Check the Below Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="carcan();">
<mx:Script>
<![CDATA[
import mx.containers.Canvas;
import mx.controls.Image;
private var images:Array;
private var images1:Array;
private const IMAGE_COUNT:uint = 5;
private var img:Image;
private var img1:Image;
private var points:flash.geom.Point;
private var offset_x:int;
private var offset_y:int;
private var canal:Canvas;
private var doDrag:Boolean;
[Embed(source='cards/2C.png')]
private var Image0:Class;
[Embed(source='cards/2D.png')]
private var Image1:Class;
[Embed(source='cards/2H.png')]
private var Image2:Class;
[Embed(source='cards/2S.png')]
private var Image3:Class;
[Embed(source='cards/3C.png')]
private var Image4:Class;
public function carcan():void
{
canal = new Canvas();
canal.setStyle("backgroundColor","blue");
canal.x=100;
canal.y=50;
canal.width=500;
canal.height=400;
this.addChild(canal);
init();
}
public function init():void
{
images = new Array(IMAGE_COUNT);
for (var i:int = 0; i < IMAGE_COUNT; i++)
{
img= new Image();
img1= new Image();
images[i] = this["Image" + i];
trace(images[i]);
img.x=(i*30)+50;
img.source=images[i];
img.id="Image"+i;
canal.addChild(img);
img.addEventListener(MouseEvent.MOUSE_DOWN, md);
img.addEventListener(MouseEvent.MOUSE_MOVE, mm);
canal.addEventListener(MouseEvent.MOUSE_OUT,smu);
img.addEventListener(MouseEvent.MOUSE_UP, mu);
}
}
public function smu(event:MouseEvent):void
{
img.alpha=1;
img.stopDrag();
doDrag=false;
setCards();
}
public function mo(event:MouseEvent):void
{
if(doDrag==true)
{
img.addEventListener(MouseEvent.MOUSE_DOWN, md);
img.addEventListener(MouseEvent.MOUSE_UP, mu);
img.stopDrag();
img.alpha=1;
img.removeEventListener(MouseEvent.MOUSE_MOVE, mm);
}
else
{
img.addEventListener(MouseEvent.MOUSE_MOVE, mm);
}
}
public function md(event:MouseEvent):void
{
img = new Image();
doDrag=true;
canal.setChildIndex(Image(event.target),images.length-1);
img.addEventListener(MouseEvent.MOUSE_MOVE, mm);
}
public function mm(event:MouseEvent):void
{
if(doDrag==true)
{
points = new Point();
images = new Array(IMAGE_COUNT);
img = new Image();
img = Image(event.target);
points.x=event.target.x;
points.y=event.target.y;
points = localToGlobal(points);
img.x=points.x;
img.y=points.y;
img.alpha=0.7;
img.addEventListener(MouseEvent.MOUSE_UP, mu);
var boundar:flash.geom.Rectangle = new Rectangle(this.x, this.y, 250, 100);
}
}
public function mu(event:MouseEvent):void
{
img.alpha=1;
canal.stopDrag();
doDrag=false;
canal.stopDrag();
doDrag=false;
var current:Image = event.currentTarget as Image;
var num1:int = current.x;
if(num1 < 50){
canal.setChildIndex(current, images.length-5);
current.y=0;
setCards();
}
if(num1 > 50 && num1 < 80){
canal.setChildIndex(current, images.length-4);
current.y=0;
setCards();
}
if(num1 > 80 && num1 < 110){
canal.setChildIndex(current, images.length-3);
current.y=0;
setCards();
}
if(num1 > 110 && num1 < 140){
canal.setChildIndex(current, images.length-2);
current.y=0;
setCards();
}
if(num1 > 140 && num1 < 170){
canal.setChildIndex(current, images.length-2);
current.y=0;
setCards();
}
if(num1 > 170){
canal.setChildIndex(current, images.length-1);
current.y=0;
setCards();
}
}
private function setCards():void{
var b:int = 0;
var a:int;
var cardsArray:Array = canal.getChildren();
for(a = 0;a < cardsArray.length; a++)
{
canal.getChildAt(a).x = 50+b;
b=b+30;
canal.getChildAt(a).y=0;
}
}
]]>
</mx:Script>
</mx:Application>
PS: I am trying to replace the drag and drop events with mouse events and get the same functionality using mouse events. Please somebody help me in this.
Hope Below Code may help you: - You can use Drag and drop as per below code and create it in AS. I have created it in MXML which will give you some idea what you are looking for: -
<?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" xmlns:local="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.core.DragSource;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.managers.DragManager;
private function doDragEnter(event:DragEvent):void
{
DragManager.acceptDragDrop(UIComponent(event.target));
}
private function doDragDrop(event:DragEvent):void
{
var img:RummyItemRenderer;
if (event.dragInitiator.parent == mainCanvas)
{
img = event.dragInitiator as RummyItemRenderer;
//mainCanvas.swapChildren(img, event.currentTarget as RummyItemRenderer);
var index:Number = mainCanvas.getChildIndex(event.currentTarget as RummyItemRenderer);
mainCanvas.removeChild(img);
mainCanvas.addChildAt(img,index);
setCardsPosition();
}
}
private function setCardsPosition():void{
var b:int = 0;
var a:int;
var cardsArray:Array = mainCanvas.getChildren();
for(a = 0;a < cardsArray.length; a++)
{
mainCanvas.getChildAt(a).x = 50+b;
b = b+30;
mainCanvas.getChildAt(a).y=20;
}
}
private function doDragStart(event:MouseEvent):void
{
var dragInitiator:RummyItemRenderer = event.currentTarget as RummyItemRenderer;
var dragSource:DragSource = new DragSource();
DragManager.doDrag(dragInitiator, dragSource, event);
}
]]>
</fx:Script>
<mx:Canvas id="mainCanvas" backgroundColor="#DDDDDD" width="400" height="200" x="50" y="50">
<local:RummyItemRenderer id="firstID" x="{mainCanvas.x}" y="20" width="200" height="80%" backgroundColor="#FF0000"
mouseDown="doDragStart(event)" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"
setImageSource="myImageURL"/>
<local:RummyItemRenderer id="secondID" x="{mainCanvas.x + 30}" y="20" width="200" height="80%" backgroundColor="#00FF00"
mouseDown="doDragStart(event)" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"
setImageSource="myImageURL"/>
<local:RummyItemRenderer id="thirdID" x="{mainCanvas.x + 60}" y="20" width="200" height="80%" backgroundColor="#0000FF"
mouseDown="doDragStart(event)" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"
setImageSource="myImageURL"/>
</mx:Canvas>
</s:Application>
RummyItemRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
[Bindable]
private var _setImageSource:String;
public function get setImageSource():String
{
return _setImageSource;
}
public function set setImageSource(sourceURL:String):void
{
_setImageSource = sourceURL;
}
]]>
</fx:Script>
<s:Image id="imageID" source="{_setImageSource}"/>
</mx:Canvas>
OK, I know that this will not sound like it is so, but I used to be really good at AS3 in versions prior to Flex 4.
I used to be able to create anything with AS3 and zero MXML.
This works fine using MXML, but I have a series of issues when I try to do the same thing in AS3.
Below is the code for both:
<?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="640"
minHeight="480"
width="100%" height="100%"
creationComplete="creationCompleteHandler();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:RemoteObject id="remotesvc" destination="ColdFusion" source="testCF-debug/cfc/myEmployees" showBusyCursor="true">
<mx:method name="getEmployees" result="getEmployeesResult(event)" fault="getEmployeesFail(event)"/>
</mx:RemoteObject>
<mx:RemoteObject id="remoteDepartment" destination="ColdFusion" source="testCF-debug/cfc/myDepartments" showBusyCursor="true">
<mx:method name="getDepartments" result="getDepartmentsResult(event)" fault="getDepartmentsFail(event)"/>
</mx:RemoteObject>
</fx:Declarations>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
.headerCustomStyle
{
color: #ffffff;
backgroundColor: #6b6767;
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.charts.Legend;
import mx.charts.PieChart;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var dgHeaderStyles:CSSStyleDeclaration;
[Bindable] private var myUsers:ArrayCollection;
public function init():void{
}
private function getEmployeesResult(event:ResultEvent):void {
employeesDg.dataProvider = event.result as ArrayCollection;
}
private function getEmployeesFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function getDepartmentsResult(event:ResultEvent):void {
departmentChart.dataProvider = event.result as ArrayCollection;
}
private function getDepartmentsFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function creationCompleteHandler():void{
remotesvc.getEmployees();
remoteDepartment.getDepartments();
}
]]>
</fx:Script>
<s:Panel title="Employees and Departments" id="empDept">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<mx:DataGrid id="employeesDg" x="10" y="88" headerStyleName="headerCustomStyle" chromeColor="{0x6b6767}">
<mx:columns>
<mx:DataGridColumn dataField="id" />
<mx:DataGridColumn dataField="firstname" />
<mx:DataGridColumn dataField="lastname" />
<mx:DataGridColumn dataField="title" />
<mx:DataGridColumn dataField="departmentid" />
<mx:DataGridColumn dataField="officephone" />
<mx:DataGridColumn dataField="cellphone" />
<mx:DataGridColumn dataField="email" />
<mx:DataGridColumn dataField="street" />
<mx:DataGridColumn dataField="city" />
<mx:DataGridColumn dataField="state" />
<mx:DataGridColumn dataField="zipcode" />
<mx:DataGridColumn dataField="office" />
<mx:DataGridColumn dataField="photofile">
<mx:itemRenderer>
<fx:Component>
<mx:Image height="20" />
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:HBox>
<mx:PieChart id="departmentChart" height="100%" width="100%">
<mx:series>
<mx:PieSeries field="budget" nameField="name" labelPosition="callout">
</mx:PieSeries>
</mx:series>
</mx:PieChart>
<mx:Legend dataProvider="{departmentChart}" />
</mx:HBox>
</s:Panel>
</s:Application>
<?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="640"
minHeight="480"
width="100%" height="100%"
creationComplete="creationCompleteHandler();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:RemoteObject id="remotesvc" destination="ColdFusion" source="testCF-debug/cfc/myEmployees" showBusyCursor="true">
<mx:method name="getEmployees" result="getEmployeesResult(event)" fault="getEmployeesFail(event)"/>
</mx:RemoteObject>
<mx:RemoteObject id="remoteDepartment" destination="ColdFusion" source="testCF-debug/cfc/myDepartments" showBusyCursor="true">
<mx:method name="getDepartments" result="getDepartmentsResult(event)" fault="getDepartmentsFail(event)"/>
</mx:RemoteObject>
</fx:Declarations>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
.headerCustomStyle
{
color: #ffffff;
backgroundColor: #6b6767;
}
</fx:Style>
<fx:Script>
<![CDATA[
import flash.utils.flash_proxy;
import mx.charts.Legend;
import mx.charts.PieChart;
import mx.charts.chartClasses.Series;
import mx.charts.series.ColumnSeries;
import mx.charts.series.PieSeries;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var employeesDg:DataGrid;
private var employeesCol1:DataGridColumn;
private var employeesCol2:DataGridColumn;
private var employeesCol3:DataGridColumn;
private var employeesCol4:DataGridColumn;
private var employeesCol5:DataGridColumn;
private var employeesCol6:DataGridColumn;
private var employeesCol7:DataGridColumn;
private var employeesCol8:DataGridColumn;
private var employeesCol9:DataGridColumn;
private var employeesCol10:DataGridColumn;
private var employeesCol11:DataGridColumn;
private var employeesCol12:DataGridColumn;
private var employeesCol13:DataGridColumn;
private var employeesCol14:DataGridColumn;
private var departmentChart:PieChart;
private var departmentChartPieSeries:PieSeries;
private var departmentChartSeries:Series;
private var departmentLegend:Legend;
private var departmentChartHbox:HBox;
private var dgHeaderStyles:CSSStyleDeclaration;
[Bindable] private var myUsers:ArrayCollection;
public function init():void{
departmentChartHbox = new HBox();
departmentChartHbox.id = "departmentChartHbox";
employeesDg = new DataGrid();
employeesDg.id = "employeesDg";
employeesDg.x = 10;
employeesDg.y = 88;
employeesDg.styleName = "";
// employeesDg.headerStyleName="headerCustomStyle";
employeesDg.chromeColor="{0x6b6767}";
employeesCol1 = new DataGridColumn;
employeesCol2 = new DataGridColumn;
employeesCol3 = new DataGridColumn;
employeesCol4 = new DataGridColumn;
employeesCol5 = new DataGridColumn;
employeesCol6 = new DataGridColumn;
employeesCol7 = new DataGridColumn;
employeesCol8 = new DataGridColumn;
employeesCol9 = new DataGridColumn;
employeesCol10 = new DataGridColumn;
employeesCol11 = new DataGridColumn;
employeesCol12 = new DataGridColumn;
employeesCol13 = new DataGridColumn;
employeesCol14 = new DataGridColumn;
employeesCol1.dataField = "id";
employeesCol2.dataField = "firstname";
employeesCol3.dataField = "lastname";
employeesCol4.dataField = "title";
employeesCol5.dataField = "departmentid";
employeesCol6.dataField = "officephone";
employeesCol7.dataField = "cellphone";
employeesCol8.dataField = "email";
employeesCol9.dataField = "street";
employeesCol10.dataField = "city";
employeesCol11.dataField = "state";
employeesCol12.dataField = "zipcode";
employeesCol13.dataField = "office";
employeesCol14.dataField = "photofile";
employeesCol14.itemRenderer;
employeesDg.addChild(employeesCol1);
employeesDg.addChild(employeesCol2);
employeesDg.addChild(employeesCol3);
employeesDg.addChild(employeesCol4);
employeesDg.addChild(employeesCol5);
employeesDg.addChild(employeesCol6);
employeesDg.addChild(employeesCol7);
employeesDg.addChild(employeesCol8);
employeesDg.addChild(employeesCol9);
employeesDg.addChild(employeesCol10);
employeesDg.addChild(employeesCol11);
employeesDg.addChild(employeesCol12);
employeesDg.addChild(employeesCol13);
employeesDg.addChild(employeesCol14);
departmentChartHbox.addChild(employeesDg);
departmentChart = new PieChart();
departmentChart.id = "departmentChart";
departmentChart.height = 320;
departmentChart.width = 240;
departmentChartSeries = new Series();
departmentChart.addChild(departmentChartSeries);
departmentChartPieSeries = new PieSeries();
departmentChartPieSeries.field = "budget";
departmentChartPieSeries.nameField = "name";
// departmentChartPieSeries.labelPosition = "callout";
departmentChartSeries.addChild(departmentChartPieSeries);
departmentLegend = new Legend();
departmentLegend.dataProvider = departmentChart;
departmentLegend.id = "departmentLegend";
departmentChartHbox.addChild(departmentChart);
departmentChartHbox.addChild(departmentLegend);
empDept.addChild(departmentChartHbox);
}
private function getEmployeesResult(event:ResultEvent):void {
employeesDg.dataProvider = event.result as ArrayCollection;
}
private function getEmployeesFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function getDepartmentsResult(event:ResultEvent):void {
departmentChart.dataProvider = event.result as ArrayCollection;
}
private function getDepartmentsFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function creationCompleteHandler():void{
remotesvc.getEmployees();
remoteDepartment.getDepartments();
}
]]>
</fx:Script>
<s:Panel title="Employees and Departments" id="empDept">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:Panel>
</s:Application>
I can not figure out how to add an itemrenderer or how to import an fx:Component, etc...
How do I do the same thing in AS3?
In case you should ask "why?", then it is because I would like to create buttons that change the PieSeries field="budget" nameField="name" attribute's values by clicking on a button which calls a function to do something like this:
myPieSeries.field="expectedCosts";
Followed by the new data being reflected in the PieChart.
Thanks in advance
OK, no errors once I figured out how to do the proper imports.
Here's a link to view:
enter link description here
<?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="1280"
minHeight="1024"
width="100%" height="100%"
creationComplete="init();creationCompleteHandler();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:RemoteObject id="remotesvc" destination="ColdFusion" source="testCF/cfc/myEmployees" showBusyCursor="true">
<mx:method name="getEmployees" result="getEmployeesResult(event)" fault="getEmployeesFail(event)"/>
</mx:RemoteObject>
<mx:RemoteObject id="remoteDepartment" destination="ColdFusion" source="testCF/cfc/myDepartments" showBusyCursor="true">
<mx:method name="getDepartments" result="getDepartmentsResult(event)" fault="getDepartmentsFail(event)"/>
</mx:RemoteObject>
</fx:Declarations>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
.headerCustomStyle
{
color: #ffffff;
backgroundColor: #6b6767;
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.charts.Legend;
import mx.charts.PieChart;
import mx.charts.chartClasses.Series;
import mx.charts.series.*;
import mx.charts.series.PieSeries;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.containers.Panel;
import mx.containers.VBox;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.DataGrid;
import mx.controls.Image;
import mx.controls.Label;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.core.ComponentDescriptor;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import spark.components.supportClasses.ItemRenderer;
import spark.layouts.VerticalLayout;
public var empDeptLabel:Label;
private var employeesDg:DataGrid;
private var employeesCol1:DataGridColumn;
private var employeesCol2:DataGridColumn;
private var employeesCol3:DataGridColumn;
private var employeesCol4:DataGridColumn;
private var employeesCol5:DataGridColumn;
private var employeesCol6:DataGridColumn;
private var employeesCol7:DataGridColumn;
private var employeesCol8:DataGridColumn;
private var employeesCol9:DataGridColumn;
private var employeesCol10:DataGridColumn;
private var employeesCol11:DataGridColumn;
private var employeesCol12:DataGridColumn;
private var employeesCol13:DataGridColumn;
private var employeesCol14:DataGridColumn;
private var employeesDgItemRend:ItemRenderer;
private var employeesDgComp:ComponentDescriptor;
private var employeesDgImg:Image;
private var departmentChart:PieChart;
private var departmentChartPieSeries:PieSeries;
private var departmentChartSeries:Series;
private var departmentLegend:Legend;
/*************************************
* Buttons
* ***********************************/
private var departBudgetBtn:Button;
private var departActualExpensesBtn:Button;
private var departEstSalaryBtn:Button;
private var departActualSalaryBtn:Button;
private var departEstTravelBtn:Button;
private var departActualTravelBtn:Button;
private var departmentChartHbox:HBox;
private var departmentChartVbox:VBox;
private var dgHeaderStyles:CSSStyleDeclaration;
[Bindable] private var myUsers:ArrayCollection;
public function init():void{
departmentChartVbox = new VBox();
departmentChartVbox.id = "departmentChartVbox";
/*************************************
* Employee DataGrid
* ***********************************/
empDeptLabel = new Label();
empDeptLabel.id = "empDeptLabel";
empDeptLabel.text = "Budget";
empDeptLabel.percentWidth = 100;
empDeptLabel.setStyle("textAlign","center");
empDeptLabel.setStyle("fontSize", 18);
empDeptLabel.setStyle("fontWeight","bold");
employeesDg = new DataGrid();
employeesDg.id = "employeesDg";
employeesDg.x = 10;
employeesDg.y = 88;
employeesDg.height = 200;
employeesDg.styleName = "";
employeesDg.setStyle("headerStyleName",".headerCustomStyle");
employeesDg.setStyle("chromeColor", 0x6b6767);
employeesCol1 = new DataGridColumn;
employeesCol2 = new DataGridColumn;
employeesCol3 = new DataGridColumn;
employeesCol4 = new DataGridColumn;
employeesCol5 = new DataGridColumn;
employeesCol6 = new DataGridColumn;
employeesCol7 = new DataGridColumn;
employeesCol8 = new DataGridColumn;
employeesCol9 = new DataGridColumn;
employeesCol10 = new DataGridColumn;
employeesCol11 = new DataGridColumn;
employeesCol12 = new DataGridColumn;
employeesCol13 = new DataGridColumn;
employeesCol14 = new DataGridColumn;
employeesCol1.dataField = "id";
employeesCol2.dataField = "firstname";
employeesCol3.dataField = "lastname";
employeesCol4.dataField = "title";
employeesCol5.dataField = "departmentid";
employeesCol6.dataField = "officephone";
employeesCol7.dataField = "cellphone";
employeesCol8.dataField = "email";
employeesCol9.dataField = "street";
employeesCol10.dataField = "city";
employeesCol11.dataField = "state";
employeesCol12.dataField = "zipcode";
employeesCol13.dataField = "office";
employeesCol14.dataField = "photofile";
employeesDgImg = new Image;
employeesDgItemRend = new ItemRenderer;
employeesDgItemRend.id = "myemployeesDgItemRend";
employeesCol14.itemRenderer = new ClassFactory(mx.controls.Image);
employeesDg.columns = [employeesCol1,employeesCol2,employeesCol3,employeesCol4,employeesCol5,employeesCol6,employeesCol7,employeesCol8,employeesCol9,employeesCol10,employeesCol11,employeesCol12,employeesCol13,employeesCol14];
/*************************************
* Department Pie Chart
* ***********************************/
departmentChart = new PieChart();
departmentChart.id = "departmentChart";
departmentChart.percentWidth = 100;
departmentChart.percentHeight = 100;
departmentChartPieSeries = new PieSeries();
departmentChartPieSeries.field = "budget";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
departmentChart.series.push(departmentChartPieSeries);
/*************************************
* Legend
* ***********************************/
departmentLegend = new Legend();
departmentLegend.dataProvider = departmentChart;
departmentLegend.id = "departmentLegend";
departmentChartHbox = new HBox();
/*************************************
* Buttons
* ***********************************/
departBudgetBtn = new Button();
departBudgetBtn.label = "Budget";
departBudgetBtn.id = "budgetBtn";
departBudgetBtn.addEventListener(MouseEvent.CLICK,whichCategory);
departActualExpensesBtn = new Button();
departActualExpensesBtn.label = "Actual Expenses";
departActualExpensesBtn.id = "actualExpensesBtn";
departActualExpensesBtn.addEventListener(MouseEvent.CLICK,whichCategory);
departEstSalaryBtn = new Button();
departEstSalaryBtn.label = "Estimated Salary";
departEstSalaryBtn.id = "estsalaryBtn";
departEstSalaryBtn.addEventListener(MouseEvent.CLICK,whichCategory);
departActualSalaryBtn = new Button();
departActualSalaryBtn.label = "Actual Salary";
departActualSalaryBtn.id = "actualsalaryBtn";
departActualSalaryBtn.addEventListener(MouseEvent.CLICK,whichCategory);
departEstTravelBtn = new Button();
departEstTravelBtn.label = "Estimated Travel";
departEstTravelBtn.id = "esttravelBtn";
departEstTravelBtn.addEventListener(MouseEvent.CLICK,whichCategory);
departActualTravelBtn = new Button();
departActualTravelBtn.label = "Actual Travel";
departActualTravelBtn.id = "actualtravelBtn";
departActualTravelBtn.addEventListener(MouseEvent.CLICK,whichCategory);
/*************************************
* Vbox and Hbox addChild
* ***********************************/
departmentChartVbox.addChild(employeesDg);
departmentChartVbox.addChild(empDeptLabel);
departmentChartVbox.addChild(departmentChart);
departmentChartVbox.addChild(departmentLegend);
/*************************************
* add buttons
* ***********************************/
departmentChartHbox.addChild(departBudgetBtn);
departmentChartHbox.addChild(departActualExpensesBtn);
departmentChartHbox.addChild(departEstSalaryBtn);
departmentChartHbox.addChild(departActualSalaryBtn);
departmentChartHbox.addChild(departEstTravelBtn);
departmentChartHbox.addChild(departActualTravelBtn);
departmentChartVbox.addChild(departmentChartHbox);
empDept.addChild(departmentChartVbox);
}
private function getEmployeesResult(event:ResultEvent):void {
employeesDg.dataProvider = event.result as ArrayCollection;
}
private function getEmployeesFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function getDepartmentsResult(event:ResultEvent):void {
departmentChart.dataProvider = event.result as ArrayCollection;
}
private function getDepartmentsFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function creationCompleteHandler():void{
remotesvc.getEmployees();
remoteDepartment.getDepartments();
}
private function whichCategory(event:MouseEvent):void{
// Alert.show(event.currentTarget.id.toString());
switch(event.currentTarget.id.toString())
{
case "budgetBtn":
departmentChartPieSeries.field = "budget";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Budget";
break;
case "actualExpensesBtn":
departmentChartPieSeries.field = "actualexpenses";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Actual Expenses";
break;
case "estsalaryBtn":
departmentChartPieSeries.field = "estsalary";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Estimated Salary";
break;
case "actualsalaryBtn":
departmentChartPieSeries.field = "actualsalary";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Actual Salary";
break;
case "esttravelBtn":
departmentChartPieSeries.field = "esttravel";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Estimated Travel";
break;
case "actualtravelBtn":
departmentChartPieSeries.field = "actualtravel";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Actual Travel";
break;
default:
departmentChartPieSeries.field = "budget";
departmentChartPieSeries.nameField = "name";
departmentChartPieSeries.setStyle("labelPosition","callout");
empDeptLabel.text = "Budget";
break;
}
departmentChart.validateNow();
}
]]>
</fx:Script>
<mx:Panel title="Employees and Departments" id="empDept">
</mx:Panel>
</s:Application>
I'm trying to practice making a simple video phone app so I'm trying to make a program to send a video and recieve a video using Cirrus from Adobe. I'm having trouble recieving the stream though. Here is the cod that I'm using:
<?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" applicationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.core.mx_internal;
import spark.components.Group;
private const SERVER:String = "rtmfp://p2p.rtmfp.net/";
private const DEVKEY:String = "MY-DEV-KEY";
[Bindable]
//Net Connection variable
private var netConnection:NetConnection;
//Sending video stream var
private var sendStream:NetStream;
//Sending video video var
private var videoSend:Video;
//Receiving video stream var
private var recvStream:NetStream;
//String for getting their ID
private var id_of_publishing_client:String;
private function init():void {
//Setup videoSend
videoSend = new Video(320,240);
videoSend.x = 10;
videoSend.y = 10;
var uic:UIComponent = new UIComponent();
uic.addChild(videoSend);
addElement(uic);
//connect
connect();
}
private function connect():void{
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
netConnection.connect(SERVER,DEVKEY);
}
private function setupStreamOutgoing():void{
//Send Stream setting up
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);
//setup camera
var cam:Camera = Camera.getCamera();
//attach the camera to the to the sendStream
sendStream.attachCamera(cam);
//publish the sendStream
sendStream.publish("media");
//attach the camera to the videoStream object
videoSend.attachCamera(cam);
}
private function getVideoReceiver():void{
id_of_publishing_client = theirID.text;
writeText("inside getVideoReceiver()");
if(id_of_publishing_client){
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
writeText("flag");
//play the recvStream
recvStream.play("media");
writeText("recvStream.play(media)");
//attach the stream to the myVid
myVid.mx_internal::videoPlayer.attachNetStream(recvStream);
}
else {
theirID.text = "Please place an ID here.";
}
}
private function netStreamHandler(event:NetStatusEvent):void{
writeText(event.info.code);
switch(event.info.code){
case "NetConnection.Connect.Success":
//Display my ID in myID.text
myID.text = netConnection.nearID;
setupStreamOutgoing();
break;
case "NetStream.Connect.Success":
break;
case "NetStream.Connect.Closed":
break;
}
}
private function writeText(txt:String):void{
txtHistory.text += txt+"\n";
}
]]>
</fx:Script>
<s:TextArea top="10" bottom="10" id="txtHistory" width="252" right="10"/>
<s:TextInput id="theirID" x="112" y="342" width="437"/>
<s:TextInput id="myID" x="112" y="312" width="437"/>
<s:Button x="10" y="312" label="My Connection" width="94" />
<s:Button x="10" y="341" label="Their Connection" width="94" click="getVideoReceiver()"/>
<mx:VideoDisplay id="myVid"
x="340"
y="10"
width="320" height="240" />
</s:Application>
Inside of the getVideoReveiver() function I'm getting the flag to go off from writeText("flag") then I get and output in the text box of:
NetStream.Play.Reset
NetStream.Play.Start
from the netStreamHandler, but the video never shows up in the receiving video element.
I'm running this is two different videos of the same computer and taking the nearID from one stream and pasting it into the textInput theirID. I'm not sure what to try next?
Here is the script that I got working for anyone who would like this as an example. All you need is a Cirrus dev key.
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.core.mx_internal;
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import spark.components.Group;
private const SERVER:String = "rtmfp://p2p.rtmfp.net/";
private const DEVKEY:String = "YOUR-DEV-KEY";
[Bindable]
//Net Connection variable that is needed to s
private var netConnection:NetConnection;
//Sending video stream var
private var sendStream:NetStream;
//Sending video video var
private var videoSend:Video;
//receiving video video var
private var videoRecv:Video;
//Receiving video stream var
private var recvStream:NetStream;
//String for getting their ID
private var id_of_publishing_client:String;
private function init():void {
//Setup videoSend
videoSend = new Video(320,240);
videoSend.x = 10;
videoSend.y = 10;
//Setup videoRecv
videoRecv = new Video(320,240);
videoRecv.x = 340;
videoRecv.y = 10;
var uic:UIComponent = new UIComponent();
uic.addChild(videoSend);
uic.addChild(videoRecv);
addElement(uic);
//connect to cirrus
connect();
}
private function connect():void{
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
netConnection.connect(SERVER,DEVKEY);
}
private function setupStreamOutgoing():void{
//Send Stream setting up
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);
//setup camera
var cam:Camera = Camera.getCamera();
//attach the camera to the to the sendStream
sendStream.attachCamera(cam);
//publish the sendStream
sendStream.publish("media");
//attach the camera to the videoStream object
videoSend.attachCamera(cam);
}
private function getVideoReceiver():void{
id_of_publishing_client = theirID.text;
writeText("inside getVideoReceiver()");
if(id_of_publishing_client){
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
writeText("flag");
//play the recvStream
recvStream.play("media");
writeText("recvStream.play(media)");
//attach the stream videoRecv
videoRecv.attachNetStream(recvStream);
}
else {
theirID.text = "Please place an ID here.";
}
}
private function netStreamHandler(event:NetStatusEvent):void{
writeText(event.info.code);
switch(event.info.code){
case "NetConnection.Connect.Success":
//Display my ID in myID.text
myID.text = netConnection.nearID;
setupStreamOutgoing();
break;
case "NetStream.Connect.Success":
break;
case "NetStream.Connect.Closed":
break;
case "NetStream.Play.Start":
break;
}
}
private function writeText(txt:String):void{
txtHistory.text += txt+"\n";
}
]]>
</fx:Script>
<s:TextArea top="10" bottom="10" id="txtHistory" width="252" right="10"/>
<s:TextInput id="theirID" x="112" y="342" width="437"/>
<s:TextInput id="myID" x="112" y="312" width="437"/>
<s:Button x="10" y="312" label="My Connection" width="94" />
<s:Button x="10" y="341" label="Their Connection" width="94" click="getVideoReceiver()"/>