A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: NEED HELP with a parent .swf and loadee .swf problem

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    8

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

    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/FlashA...aliaPlayer.swf

    BUT it is supposed to load into the API here:

    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...3-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/FlashA...aliaPlayer.swf)


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


    var url:String = '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';
    // 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:
    function initVideoPlayer():void {

    trace("Am I loading?");
    //positionBar.addEventListener(ProgressEvent.PROGRES S, 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/

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

    //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,removeAn imalia);
    //AnimalVideoOut.addEventListener(Event.CLOSE,remove Sequence);
    }

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


    //removeChild(AnimalVideoOut);
    }


    // END ANIMALIA video LOADER

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Quote Originally Posted by QuickPromise View Post
    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()
    You need to trace individual objects to see what is null. If your trace does not show up the error is earlier in the script.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center