# NEED HELP with a parent .swf and loadee .swf problem

**URL:** <https://forum.kirupa.com/t/need-help-with-a-parent-swf-and-loadee-swf-problem/295770>\
**Category:** flash\
**Created:** [September 4, 2009, 1:23am UTC](https://forum.kirupa.com/t/need-help-with-a-parent-swf-and-loadee-swf-problem/295770 "2009-09-04T01:23:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CallClass](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@CallClass](https://forum.kirupa.com/u/CallClass)\
**Post date:** [September 4, 2009, 1:23am UTC](https://forum.kirupa.com/t/need-help-with-a-parent-swf-and-loadee-swf-problem/295770/1 "2009-09-04T01:23:14Z")

</div>

I have a load issue with my video player since I added a timer and RED play progess bar to it. It plays perfectly by itself here:

[http://www.playingthepoet.com/FlashAPI/AnimaliaPlayer.swf](http://www.playingthepoet.com/FlashAPI/AnimaliaPlayer.swf)

BUT it is supposed to load into the API here:

[http://www.playingthepoet.com/](http://www.playingthepoet.com/)

Please click on “Animalia - Verse From The Zoo”. The .swf still loads but the video is not playing. The blue load progress and the red play progress, timer and video are not engaging. I added the red play progress and timer functions to what I had previously built via a video player I found here:

[http://www.thetechlabs.com/tutorials/audionvideo/how-to-build-a-as3-videoplayer/](http://www.thetechlabs.com/tutorials/audionvideo/how-to-build-a-as3-videoplayer/)

When I test locally, loading the Video Player .swf into the parent API .swf, (and click on “Animalia”) I get an error message that says:“TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at ScrubbingPlayer2\_fla::MainTimeline/initVideoPlayer()  
at ScrubbingPlayer2\_fla::MainTimeline/frame1()  
removing animalia  
Im looking for [object Loader] and I am [object MainTimeline]  
[object Loader]  
TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at ScrubbingPlayer2\_fla::MainTimeline/unloadThisSkin()”

So it’s a problem concerning how the

“initVideoPlayer()”

function cannot talk to the parent API.

Do I need some kind of parent and child Dispatch Method to resolve this? As I learn AS3, I’m finding the most complex problems are load issues between parent and loadee .swf files. And this is another one. I’ve attached all the code for the Video Player, and the relevant loading code from the parent API below. My question is this: How do I code the parent and loadee .swfs to make the video play WHEN IT LOADS INTO THE PARENT API just as it plays by itself on the above first URL? Phew!! Sorry if that’s over-worded but just trying to be clear. Many thanks. WF

LOADEE VIDEO PLAYER CODE:  
(PLAYS ALONE AT:  
[http://www.playingthepoet.com/FlashAPI/AnimaliaPlayer.swf](http://www.playingthepoet.com/FlashAPI/AnimaliaPlayer.swf))

import fl.events.SliderEvent;  
import fl.controls.ProgressBarMode;  
import flash.display.\*;

var url:String = ‘[http://www.playingthepoet.com/FlashAPI/Sequence01.flv](http://www.playingthepoet.com/FlashAPI/Sequence01.flv)’;  
var request:URLRequest = new URLRequest(url);

//PLAYER progress - red horizontal bar

const BUFFER\_TIME:Number = 8;  
const DEFAULT\_VOLUME:Number = 0.6;  
const DISPLAY\_TIMER\_UPDATE\_DELAY:int = 10;

var bolLoaded:Boolean = false;

// flag for progress scrubbing  
var bolProgressScrub:Boolean = false;  
// object holds all meta data  
var nc:NetConnection;  
var ns:NetStream;  
//VOLUME VAR FIRST THING CUT  
var objInfo:Object;  
// url to flv file  
var strSource:String = ‘[http://www.playingthepoet.com/FlashAPI/Sequence01.flv](http://www.playingthepoet.com/FlashAPI/Sequence01.flv)’;  
// timer for updating player (progress, volume…)  
var tmrDisplay:Timer;

//var vid:Video;  
// LOGIC is saying we don’t need a video object because there’s one sourced to the stage!!! I hope.

pauseBtn.buttonMode = true;  
pauseBtn.visible = false;  
playBtn.buttonMode = true;  
stopBtn.buttonMode = true;  
//VIDEO player RED play progress and timer functionality I found at [http://www.thetechlabs.com](http://www.thetechlabs.com):  
function initVideoPlayer():void {

```
trace("Am I loading?");

```

[//positionBar.addEventListener](https://positionBar.addEventListener)(ProgressEvent.PROGRESS, loadListener);

stage.addEventListener( MouseEvent.MOUSE\_UP, mouseReleased);  
//BUTTON listeners  
playBtn.addEventListener(MouseEvent.CLICK, playClicked);  
pauseBtn.addEventListener(MouseEvent.CLICK, pauseClicked);

tmrDisplay = new Timer(DISPLAY\_TIMER\_UPDATE\_DELAY);  
tmrDisplay.addEventListener(TimerEvent.TIMER, updateDisplay);

nc = new NetConnection();  
nc.addEventListener(NetStatusEvent.NET\_STATUS, netStatusHandler);  
nc.connect(null);

ns = new NetStream(nc);  
ns.addEventListener(NetStatusEvent.NET\_STATUS, netStatusHandler);  
ns.client = this;  
ns.bufferTime = BUFFER\_TIME;

vid.attachNetStream(ns);

positionBar.mode = ProgressBarMode.POLLED;  
positionBar.source = ns;

//END of Video Player initialiser  
}

function loadListener(event:ProgressEvent) {  
var percentLoaded:int = event.target.bytesLoaded / event.target.bytesTotal \* 100;

```
trace("Percent loaded: " + percentLoaded + "%"); 

```

}

function playClicked(e:MouseEvent):void {  
if(!bolLoaded) {  
ns.play(strSource);  
bolLoaded = true;

```
} else {
	ns.resume();
}

vid.visible = true;

pauseBtn.visible	= true;
playBtn.visible = false;

```

}  
function pauseClicked(e:MouseEvent):void {

```
ns.pause();

// switch play/pause visibility
pauseBtn.visible	= false;
playBtn.visible = true;

```

}

/\*function playHandler(event:MouseEvent):void {  
ns.resume();  
pauseBtn.visible = true  
playBtn.visible = false   
}  
function pauseHandler(event:MouseEvent):void {  
ns.togglePause();  
pauseBtn.visible = false  
playBtn.visible = true   
}  
\*/  
function progressScrubberClicked(e:MouseEvent):void {  
// set progress scrub flag to true  
bolProgressScrub = true;

```
// start drag
//btnProgressScrubber.startDrag(false, new Rectangle(0, 2, 357, 0));

```

}  
function mouseReleased(e:MouseEvent):void {

```
bolProgressScrub	= false;

//mcFillRed.stopDrag();

//mcFillRed.width	= mcFillRed.x + 5;	

```

}

function updateDisplay(e:TimerEvent):void {

```
	mcFillRed.x = ns.time * 3.6 - objInfo.duration - 39;
	
	
lblTimeDuration.htmlText = "" + formatTime(ns.time) + " / " + formatTime(objInfo.duration);

```

}  
function onMetaData(info:Object):void {  
// stores meta data in a object  
objInfo = info;

```
// now we can start the timer because
// we have all the neccesary data
tmrDisplay.start();

```

}  
function netStatusHandler(event:NetStatusEvent):void {  
switch (event.info.code) {  
case “NetStream.Play.StreamNotFound”:  
trace("Stream not found: " + strSource);  
break;  
case “NetStream.Play.Stop”:  
stopVideoPlayer();  
break;  
}  
}  
function stopVideoPlayer():void {  
ns.pause();  
ns.seek(0);

```
vid.visible = false;

pauseBtn.visible	= false;
playBtn.visible = true;

```

}  
function formatTime(t:int):String {  
var s:int = Math.round(t);  
var m:int = 0;  
if (s \> 0) {  
while (s \> 59) {  
m++;  
s -= 60;  
}  
return String((m \< 10 ? “0” : “”) + m + “:” + (s \< 10 ? “0” : “”) + s);  
} else {  
return “00:00”;  
}  
}  
// closeHandler function is only needed if the swf is played by itself and NOT loaded into another swf  
/\*  
stopBtn.addEventListener(MouseEvent.CLICK, closeHandler)  
function closeHandler(event:MouseEvent):void {  
ns.pause();  
ns.seek(0);  
pauseBtn.visible = false  
playBtn.visible = true  
}  
\*/  
var AnimalSkinLoader:Loader = new Loader();  
stopBtn.addEventListener(MouseEvent.MOUSE\_DOWN, unloadThisSkin);  
function unloadThisSkin(event:MouseEvent):void {   
//FI: dispatch event here instead of making new function   
this.parent.dispatchEvent(new Event(Event.CLOSE));   
//FI: corrected below - sorry for the confusion- AnimalSkinLoader is detected properly  
trace('Im looking for ‘+ AnimalSkinLoader +’ and I am '+this);  
trace(this.parent);  
ns.pause();  
ns.seek(0);  
pauseBtn.visible = false  
playBtn.visible = true  
}  
//VOLUME slider  
var volumeTransform:SoundTransform = new SoundTransform();  
mySlider.value = volumeTransform.volume;  
mySlider.minimum = 0;  
mySlider.maximum = 4;  
mySlider.addEventListener(SliderEvent.CHANGE, volumeChangeHandler);

function volumeChangeHandler(event:SliderEvent):void {

```
		volumeTransform.volume = event.value;
		ns.soundTransform = volumeTransform;

```

}  
initVideoPlayer();

=-=-=-=-==-=-=-=-

RELEVANT PARENT API CODE WHEN YOU CLICK ON “ANIMALIA” AT  
:[http://www.playingthepoet.com/](http://www.playingthepoet.com/)

var AnimalLoader:Loader = new Loader();  
var initVideoPlayer:Function;  
AnimalLoader.load(new URLRequest(‘ScrubbingPlayer2.swf’));

[//AnimalLoader.load](https://AnimalLoader.load)(new URLRequest(‘112thSequence.swf’));

Animalia2.addEventListener(MouseEvent.MOUSE\_DOWN, loadFromAnimalia);

function loadFromAnimalia(event:MouseEvent):void {  
addChild(AnimalLoader);  
initVideoPlayer = new Function();

```
//addChild(AnimalVideoOut);

AnimalLoader.addEventListener(Event.CLOSE,removeAnimalia);
//AnimalVideoOut.addEventListener(Event.CLOSE,removeSequence);

```

}

//FI NOTE: here is the closing function:  
function removeAnimalia(event:Event = null):void{  
trace(‘removing animalia’);  
removeChild(AnimalLoader);

```
//removeChild(AnimalVideoOut);

```

}

// END ANIMALIA video LOADER
