I have a kiosk program that is intended to run a random video if it hasn’t been used for a predetermined interval. Up until this morning it was running, but extended testing showed that it would fall over after a period of 1/2 hour or so, which I took to be a memory issue. I added the two lines in the frame 2 code [COLOR=“Blue”]‘stream_ns.close();[/COLOR]’ and [COLOR=“blue”]‘video_vd = null’[/COLOR] to see if this solved the problem.
Instead (and despite the fact I’ve remmed those 2 statements back out again, I now get the following whenever the program jumps to frame 2:
[COLOR=“blue”]TypeError: Error #1009: Cannot access a property or method of a null object reference.
at EBMTMan8_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at EBMTMan8_fla::MainTimeline/playVid()
at EBMTMan8_fla::MainTimeline/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()[/COLOR]
What the hell’s gone wrong?
The frame 1 code is:
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.*;
//import flash.display.Shape;
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.utils.Dictionary;
import fl.video.VideoEvent;
stop();
var home:MovieClip=this;
orgLabels.alpha=0.7;
//idle timer
var timer:Timer=new Timer(2000);
timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
timer.start();
function onTimer(evt:TimerEvent):void {
//trace("time up");
playVid();
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, doMouseMove, false, 0, true);
function doMouseMove(evt:MouseEvent):void {
timer.reset();
timer.start();
}
// custom cursor
Mouse.hide();
customCursor.startDrag(true);
stage.addEventListener(Event.ENTER_FRAME, moveCursor);
function moveCursor(event:Event) {
customCursor.x=mouseX;
customCursor.y=mouseY;
customCursor.mouseEnabled=false;
customCursor.mouseChildren=false;
}
video_btn.addEventListener(MouseEvent.MOUSE_UP, playVideo, false, 0, true);
function playVid():void {
timer.removeEventListener(TimerEvent.TIMER, onTimer);
closeAll();
stage.removeEventListener(MouseEvent.MOUSE_MOVE, doMouseMove)
stage.removeEventListener(Event.ENTER_FRAME, moveCursor)
mouth.removeEventListener(MouseEvent.MOUSE_UP, openMouth);
mouth.removeEventListener(MouseEvent.MOUSE_OVER, overCursor);
mouth.removeEventListener(MouseEvent.MOUSE_OUT, outCursor);
//etc.
gotoAndStop(2);
}
function playVideo(evt:MouseEvent):void {
gotoAndStop(2);
}
//body parts
mouth.addEventListener(MouseEvent.MOUSE_UP, openMouth, false, 0, true);
mouth.addEventListener(MouseEvent.MOUSE_OVER, overCursor, false, 0, true);
mouth.addEventListener(MouseEvent.MOUSE_OUT, outCursor, false, 0, true);
//etc.
}
and frame 2 code is:
stop();
import flash.display.MovieClip;
import flash.events.Event;
var poseList:Array=["cold.f4v","rubNeck.f4v"];
var poseNo:Number = Math.round(Math.random()*(poseList.length-1));
var randPose:String=poseList[poseNo];
video_vd.x=0;
video_vd.y=0;
video_vd.width=1080;
video_vd.height=1920;
var video_vd:Video = new Video();
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream=new NetStream(connection_nc);
stream_ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
stream_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
video_vd.attachNetStream(stream_ns);
addChild(video_vd);
stream_ns.play("poses/" + randPose);
//stop the stream immediately so we can buffer in advance
stream_ns.pause();
//set the video back at 0 start
stream_ns.seek(0);
//every 500ms execute the function checkLoaded with param = stream_ns
var loaded_num:Number=setInterval(checkLoaded,500,stream_ns);
function checkLoaded(my_ns:NetStream) {
//calculate the percent loaded
var percentLoaded:Number=Math.round(my_ns.bytesLoaded/my_ns.bytesTotal*100);
//If the video has loaded completly then resume playing the movie
if (percentLoaded>=100) {
stream_ns.resume();
clearInterval(loaded_num);
}
}
function netStatusHandler(event:NetStatusEvent):void {
//trace(event.info.code);
if (event.info.code=="NetStream.Play.Stop") {
//stream_ns.close();
removeChild(video_vd);
//video_vd = null;
gotoAndStop(1);
}
}
function asyncErrorHandler(event:AsyncErrorEvent):void {
//trace(event.text);
}