I have 2 NetStream objects that I am trying to assign 2 videos to (one to each), and then, because I have 2 native windows, I use stage.addChild(video);
and secondWindow.stage.addChild(video2);
. I am using stream.play("scene1.f4v");
and stream2.play("scene1A.f4v");
to specify the files for the streams. I am now diagnosing an error, because the videos are not playing. Instead, I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Function/detectText()[/Users/Jared/Documents/Adobe Flash Builder 4.7/InTheAirNet_MultiviewPlayer/src/InTheAirNet_MultiviewPlayer.as:124]
Line 124 is secondWindow.stage.addChild(video2);
. Is this error due to an issue with my file URLS? I have the video files in a folder named assets
in the structure for my application.
I think that is enough, but I will include my code too- just in case:
package
{
import flash.desktop.NativeApplication;
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowSystemChrome;
import flash.display.Screen;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.KeyboardEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class InTheAirNet_MultiviewPlayer extends Sprite {
public var secondWindow:NativeWindow;
public static var nativeApplication:Object;
private var connection:NetConnection;
private var stream:NetStream;
private var stream2:NetStream;
private var video:Video;
private var video2:Video;
public function InTheAirNet_MultiviewPlayer() {
// Ouput screen sizes and positions (for debugging)
for each (var s:Screen in Screen.screens) trace(s.bounds);
// Make primary (default) window's stage go fullscreen
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
stage.color = 0xC02A2A; // red
// Create fullscreen window on second monitor (check if available first)
if (Screen.screens[1]) {
// Second window
var nwio:NativeWindowInitOptions = new NativeWindowInitOptions();
nwio.systemChrome = NativeWindowSystemChrome.NONE;
secondWindow = new NativeWindow(nwio);
secondWindow.bounds = (Screen.screens[1] as Screen).bounds;
secondWindow.activate();
// Second window's stage
secondWindow.stage.align = StageAlign.TOP_LEFT;
secondWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
secondWindow.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
secondWindow.stage.color = 0x387D19; // green
}
//Create array of scenes and their overlays
var videos:Array = [
{
primary:'scene1.f4v',
secondary:['scene1A.f4v','scene1B.f4v']
},
{
primary:'scene2.f4v',
secondary:['scene2A.f4v','scene2B.f4v']
},
{
primary:'scene3.f4v',
secondary:['scene3A.f4v','scene3B.f4v']
},
{
primary:'scene4.f4v',
secondary:['scene4A.f4v','scene4B.f4v']
},
{
primary:'scene5.f4v',
secondary:['scene5A.f4v','scene5B.f4v']
}
]
//Keyboard event listener and key assignment
stage.addEventListener(KeyboardEvent.KEY_DOWN, detectText);
function detectText(keyboardevent:KeyboardEvent):void {
if (keyboardevent.keyCode == 38) { //UP
//Previous scene
}
if (keyboardevent.keyCode == 40) { //DOWN
//Next scene
}
if (keyboardevent.keyCode == 37) { //LEFT
//Previous overlay
}
if (keyboardevent.keyCode == 39) { //RIGHT
//Next overlay
}
if (keyboardevent.keyCode == 27) { //ESCAPE
//Terminate application
NativeApplication.nativeApplication.exit();
}
//START static video objects for BETA
//Create the NetConnection
connection = new NetConnection();
//Set NetConnection to streaming mode; null specifies NO media server connection
connection.connect(null);
//Create the NetStream
stream = new NetStream(connection);
stream2 = new NetStream (connection);
//Set NetStream client to recieve certain events
stream.client = this;
stream2.client = this;
//Create video objects
var video:Video = new Video();
var video2:Video = new Video();
//Add video objects to their stages
stage.addChild(video);
secondWindow.stage.addChild(video2);
//Attach the NetStream to the video object
video.attachNetStream(stream);
video2.attachNetStream(stream2);
//Set the default buffer time to 1 second
stream.bufferTime = 1;
stream2.bufferTime = 1;
//Tell the stream to recieve the video
stream.receiveVideo(true);
stream2.receiveVideo(true);
//Play a F4V file
stream.play("scene1.f4v");
stream2.play("scene1A.f4v");
}
}
}
}