StageVideoAvailabilityEvent not found - actionscript-3

Im Working on Air Application and heres my Class
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.StageVideoAvailabilityEvent;
import flash.geom.Rectangle;
import flash.media.StageVideo;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class presentation extends Sprite
{
private const VIDEO_FILE_URL:String = "assets/Presentation_Demo_02.mp4";
private var video:Video;
private var stageVideo:StageVideo;
private var nc:NetConnection;
private var ns:NetStream;
private var streamClient:Object;
public function presentation()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//stage.displayState = StageDisplayState.FULL_SCREEN;
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(event:Event):void
{
trace("All Works");
initStream();
removeEventListener(Event.ADDED_TO_STAGE,init);
stage.addEventListener(Event.RESIZE, stageResize);
addEventListener(Event.ENTER_FRAME,update);
}
private function initStream():void
{
streamClient = new Object();
streamClient.onMetaData = onMetaData;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = streamClient;
addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY,onChange);
}
private function onChange(event:StageVideoAvailabilityEvent):void
{
trace(event.availability);
}
private function stageResize(event:Event):void
{
}
private function update(event:Event):void
{
}
public function onMetaData(e:Object):void
{}
}
}
on the line where addEventListener for StageVideoAvailabilityEvent i got Error in Flash Builder
Type was not found or was not a compile-time constant: StageVideoAvailabilityEvent.
what can i do

Be sure that you are using a version of Adobe AIR that supports StageVideo. (I recommend you to download the latest version, 17).
Update your Adobe AIR Application Description file to the respective AIR version. (in this case 17)
<application xmlns="http://ns.adobe.com/air/application/17.0">
Also, be sure that you add an extra compiler argument to indicate the respective SWF version (fro AIR 17, should be 28:
-swf-version=28

Related

StageVideo problems

i'm trying some examples founded on the web but don't works...
the code :
package{
import flash.display.Sprite;
import flash.events.StageVideoAvailabilityEvent;
import flash.media.StageVideo;
import flash.events.StageVideoEvent;
import flash.geom.Rectangle;
import flash.media.StageVideoAvailability;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.display.DisplayObjectContainer;
public class myStageVideo extends Sprite{
private var stageVideoAvail:Boolean;
private var sv:StageVideo;
public function myStageVideo(container:DisplayObjectContainer){
container.addChild(this);
container.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onAvail);
}
private function onAvail(e:StageVideoAvailabilityEvent):void{
trace("arrivato a onAvail");
stageVideoAvail = (e.availability == StageVideoAvailability.AVAILABLE);
initVideo();
}
private function initVideo():void{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
stageVideoAvail = true;
if(stageVideoAvail){
sv = stage.stageVideos[0];
sv.addEventListener(StageVideoEvent.RENDER_STATE, onRender);
sv.attachNetStream(ns);
trace('available');
}
else{
var vid:Video = new Video(1024, 768);
addChild(vid);
vid.attachNetStream(ns);
trace('not');
}
ns.play('video.mp4');
}
private function onRender(e:StageVideoEvent):void{
sv.viewPort = new Rectangle(0, 0, 1024, 768);
}
public function onMetaData(e:Object):void{
}
public function onXMPData(e:Object):void{
}
}
}
what am I doing wrong? I'm trying from a week, but nothing...
the video.mp4 is in the same folder.
i think 1 error
It is the way in which I add the child to the container

AS3: Parameter child must be non-null

doing augmented reality app tut from YouTube. I'm newbie at this whole FLARTool kit and papervision staff. Eternal gratitude to the helpers.
i've got this script:
package
{
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.ByteArray;
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.support.pv3d.FLARBaseNode;
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
[SWF(width="640", height="480", frameRate="30", backgroundColor="#ffffff")]
public class test extends Sprite
{
[Embed(source="marker15.pat", mimeType="application/octet-stream")]
private var marker:Class;
[Embed(source="camera_para.dat", mimeType="application/octet-stream")]
private var cam_params:Class;
//createFLAR variables
private var ar_params:FLARParam;
private var ar_marker:FLARCode;
//createCam variables
private var ar_vid:Video
private var ar_cam:Camera
//createBMP vairiables
private var ar_bmp:BitmapData;
private var ar_raster:FLARRgbRaster_BitmapData;
private var ar_detection:FLARSingleMarkerDetector;
//createPapervision variables
private var ar_scene:Scene3D;
private var ar_3dcam:org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
private var ar_basenode:FLARBaseNode;
private var ar_viewport:Viewport3D;
private var ar_renderengine:BasicRenderEngine;
private var ar_transmat:FLARTransMatResult;
private var ar_cube:Cube;
public function test()
{
createFLAR();
createCam();
createBMP();
createPapervision();
addEventListener(Event.ENTER_FRAME, loop);
}
public function createFLAR()
{
ar_params= new FLARParam();
ar_marker= new FLARCode(16,16);
ar_params.loadARParam(new cam_params() as ByteArray);
ar_marker.loadARPatt(new marker());
}
public function createCam()
{
ar_vid= new Video(640, 480);
ar_cam= Camera.getCamera();
ar_cam.setMode(640,480,30);
ar_vid.attachCamera(ar_cam);
addChild(ar_vid);
}
public function createBMP()
{
ar_bmp= new BitmapData(640,480);
ar_bmp.draw(ar_vid);
ar_raster= new FLARRgbRaster_BitmapData(ar_bmp);
ar_detection= new FLARSingleMarkerDetector(ar_params, ar_marker,80);
}
public function createPapervision()
{
ar_scene= new Scene3D();
ar_3dcam= new org.libspark.flartoolkit.support.pv3d.FLARCamera3D(ar_params);
ar_basenode= new FLARBaseNode();
ar_renderengine= new BasicRenderEngine();
ar_transmat= new FLARTransMatResult();
var ar_light:PointLight3D= new PointLight3D();
ar_light.x= 1000;
ar_light.y= 1000;
ar_light.z= -1000;
var ar_bitmap:BitmapFileMaterial;
ar_bitmap=new BitmapFileMaterial ("LBP2.jpg");
ar_bitmap.doubleSided=true;
ar_cube=new Cube(new MaterialsList({all:ar_bitmap}), 80, 80, 80);
ar_scene.addChild(ar_basenode);
ar_basenode.addChild(ar_cube);
addChild(ar_viewport);
}
private function loop(e:Event):void
{
ar_bmp.draw(ar_vid);
ar_cube.rotationX +=4;
ar_cube.rotationY +=6;
try
{
if(ar_detection.detectMarkerLite(ar_raster, 80) && ar_detection.getConfidence()>0.5)
{
ar_detection.getTransformMatrix(ar_transmat);
ar_basenode.setTransformMatrix(ar_transmat);
ar_renderengine.renderLayers(ar_scene, ar_3dcam, ar_viewport);
}
}
catch (e:Error){}
}
}
}
when i'm running test I'm getting this log:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at test/createPapervision()[C:\Users\Omer Hacohen\Adobe Flash Builder 4.7\test\src\test.as:103]
at test()[C:\Users\Omer Hacohen\Adobe Flash Builder 4.7\test\src\test.as:58]
what does it means? No need to tell the application does open the camera but the cube that supposed to sit on the marker does not appear
You are recieving the error because of the following line in the createPapervision method:
addChild(ar_viewport);
From your posted code, you're never initializing that variable (ar_viewport), so it's null when you try to add it.
Try this:
ar_viewport = new Viewport3D(stage.stageWidth,stage.stageHeight);
addChild(ar_viewport);

AS3 Preloader not updating screen

I've been struggling with a Flash preloader. I just want it to update the text on the screen with the current percentage. Now it basically works as the trace outputs the correct percentages, but it won't update the textfield I have on the screen. Once the trace gets to 100% however, the code does output "100" on the screen, but not until it's all loaded. I don't have the Flash IDE and am just using pure Actionscript with FlashDevelop. Here's my code:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.Loader;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldType;
public class Main extends Sprite
{
public var myLoader:Loader = new Loader();
public var image:String = "tmp/Avengers-poster.jpg";
private var Title:TextField;
private var txt:String;
private var Form:TextField;
public function Main():void {
textbox("This is the title","box",100,100,200,30);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest(image);
myLoader.load(fileRequest);
}
public function onProgressStatus(e:ProgressEvent):void {
// this is where progress will be monitored
var perc:int = Math.ceil((e.bytesLoaded/e.bytesTotal)*100);
txt = perc.toString();
Title.text = txt;
addChild (Title);
trace(perc);
}
public function onLoaderReady(e:Event):void {
// the image is now loaded, so let's add it to the display tree!
addChild(myLoader);
}
private function textbox (title_str:String,form_name:String,x:int,y:int,width:int,height:int):void {
Title = new TextField ();
Title.text = title_str;
Title.selectable = false;
Title.setTextFormat (new TextFormat ("Arial", 12, 0x777777, true));
txt = ".";
Title.x = x;
Title.y = y;
addChild (Title);
}
}
}
Thanks for your help.
Darryl
This will work. Don't recreate the TextField on each status. You only need to addChild once and update the reference to it.
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
public class Main extends Sprite
{
public var myLoader:Loader = new Loader();
public var image:String = "http://apod.nasa.gov/apod/image/0605/titan5km_huygens_big.jpg";
private var Title:TextField;
private var Form:TextField;
public function Main():void {
createTextField("This is the title","box",100,100,200,30);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest(image);
myLoader.load(fileRequest);
}
public function onProgressStatus(e:ProgressEvent):void {
// this is where progress will be monitored
var perc:int = Math.ceil((e.bytesLoaded/e.bytesTotal)*100);
Title.text = perc.toString();
}
public function onLoaderReady(e:Event):void {
// the image is now loaded, so let's add it to the display tree!
addChild(myLoader);
}
private function createTextField (title_str:String,form_name:String,x:int,y:int,width:int,height:int):void {
Title = new TextField();
Title.text = title_str;
Title.selectable = false;
Title.setTextFormat (new TextFormat ("Arial", 12, 0x777777, true));
Title.text = ".";
Title.x = x;
Title.y = y;
addChild (Title);
}
}
}

NetStream Info Returning 0's (Icecast Stream)

I've searched high and low for a fix to this issue, but cannot find ANYTHING on why almost all the properties are being returned as 0.
I am using FLV wrapping to pull a live audio stream from Icecast (since Adobe, 15 years later, still haven't fixed their live audio memory leak issue). It works great, everything functions perfectly.
However, I'm wanting to create a bandwidth monitor (for my iPhone port, and for my normal Flash player)... But whenever I retrieve netStreamInfo it returns as 0! For dataBytesPerSecond, audioBytesPerSecond, byteCount, dataByteCount, nearly EVERY SINGLE PROPERTY returns 0. I have this run on a 1-second timer.
Here's the total info output:
currentBytesPerSecond=0
byteCount=0
maxBytesPerSecond=0
audioBytesPerSecond=0
audioByteCount=0
videoBytesPerSecond=0
videoByteCount=0
dataBytesPerSecond=0
dataByteCount=0
playbackBytesPerSecond=16296.296296296296
droppedFrames=0
audioBufferLength=0.072
videoBufferLength=0
dataBufferLength=0
audioBufferByteLength=1540
videoBufferByteLength=0
dataBufferByteLength=0
srtt=0
audioLossRate=0
videoLossRate=0 Data Bytes Per Second
That output was about 5 minutes in. I noted the playBackBytesPerSecond never changed, and the audioBufferByteLength liked to switch between 1540 and 23xx randomly.
Can anyone pleaaase help me out here?
My actionscript:
package
{
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.text.TextFieldAutoSize;
import flash.text.TextField;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.NetStatusEvent;
import flash.utils.Timer;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.display.Loader;
import flash.errors.IOError;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.net.NetStreamInfo;
import flash.utils.ByteArray;
import flash.media.*
public class soundContainer extends Sprite
{
public var slider:SliderMC = new SliderMC();
private var _video:Video;
private var _stream:NetStream;
private var _playbackTime:TextField;
private var _duration:uint;
private var _timer:Timer;
private var _soundChannel:SoundChannel;
public var audioTransform:SoundTransform = new SoundTransform();
public var _URL:String;
public var flvUrl:String = "s";
public var dragging:Boolean = false;
public var rectangle:Rectangle = new Rectangle(0,0,100,0);
private var ba:ByteArray;
private var bn;
public function soundContainer() {
addEventListener(Event.ADDED_TO_STAGE, init);
}
public function init(e:Event):void
{
ba = new ByteArray();
slider.x = 73.85;
slider.y = 10.95;
addChild(slider);
slider.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);
_timer = new Timer(1000);
_timer.addEventListener(TimerEvent.TIMER, onTimer);
_timer.start();
}
public function dragIt(e:MouseEvent):void
{
slider.slider_mc.startDrag(false, rectangle);
dragging = true;
slider.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
public function dropIt(e:MouseEvent = null):void
{
if (dragging)
{
slider.slider_mc.stopDrag();
dragging = false;
}
}
public function adjustVolume(e:Event):void
{
var vol:Number = slider.slider_mc.x / 100;
var st:SoundTransform = new SoundTransform(vol);
SoundMixer.soundTransform = st;
}
public function playMyFlv(flvUrl)
{
_URL = flvUrl;
_video = new Video();
var connection:NetConnection = new NetConnection();
connection.connect(null);
_stream = new NetStream(connection);
_stream.soundTransform = audioTransform;
_stream.play(flvUrl);
var Client:Object = new Object();
_stream.client = Client;
_video.attachNetStream(_stream);
addChild(_video);
}
public function stopMyFlv()
{
SoundMixer.stopAll();
trace("stop");
try
{
_stream.close();
}
catch (error:IOError)
{
}
}
private function onNetStatus(e:NetStatusEvent)
{
}
private function onTimer(t:TimerEvent):Number
{
trace(_stream.info + " Data Bytes Per Second");
}
public function onIOError(e:IOError)
{
trace("Failed to load");
}
}
}

Build the connection between Arduino and Flex 4.0 via JSON

I try to make a connection between arduino and Flex 4.0, I added the JSON lib and also as3corelib.swc to Flex. When I run the Flex file the connection between PC to arduino is working (I can see it in SERPROXY window) and also I don't have any problems in Flex window, I added the SWF file of Flex to the list at //http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html, Bu the reading result is not shows in the SWF, I couldn't understand why !, thanks for help
and here the code
package
{
import com.adobe.serialization.json.JSON;
//http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
public class deneme extends Sprite
{
private var magnetic:Socket=new Socket("localhost",5331);
private var magneticValue:Number=0;
private var distance:Number;
private var newText:TextField=new TextField();
private var listText:TextField=new TextField();
private var MNx:Number;
private var MNy:Number;
private var MNz:Number;
private var d:Object={"x":null, "y":null, "z":null};
public function deneme()
{
socketDataHandler();
}
private function socketDataHandler():void
{
newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
d= JSON.decode(newText.text);
MNx=d["x"];
MNy=d["y"];
MNz=d["z"];
listText.x=10;
listText.y=10;
listText.width=600;
listText.height=100;
listText.text=newText.text;
addChild(newText);
}
}
}
package
{ import com.adobe.serialization.json.JSON;
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
import mx.rpc.events.ResultEvent;
public class deneme2 extends Sprite
{
private var newText:TextField=new TextField();
private var listText:TextField=new TextField();
private var magnetic:Socket=new Socket("localhost",5331);
private var MNx:Number;
private var MNy:Number;
private var MNz:Number;
private var d:Object={"x":null, "y":null, "z":null};
public function deneme2()
{
magnetic.addEventListener(ProgressEvent.SOCKET_DATA,getDATA);
}
private function getDATA(event:ProgressEvent):void
{
newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
d= JSON.decode(newText.text);
MNx=d["x"];
MNy=d["y"];
MNz=d["z"];
listText.x=10;
listText.y=10;
listText.width=600;
listText.height=100;
listText.text="X="+String(MNx)+" Y="+String(MNy)+" Z="+String(MNz);
addChild(listText);
}
}
}