TwelvestoneFlash

onMetaData // netstream // obj.duration losing scope with in an as2 class


Sign in

  • Waiting for Godot ( 750 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 6.1 k posts )
    general front end design an...
  • Back End ( 10 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 13 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
pyrogen
 
2005-09-28

hi

i am trying to port over a net stream player i made into an as2 class... everything is grand..... except thr duration property from with in the onMetaData function gets lost to the class it self.

the duration propery traces fine, i howerver cannot figure out how to write the duration to a class property..... becuse with in the onMetaData call, the scope to the class is lost

any ideas?

thanks for your time

d

persist
 
2005-09-28

can you post an abbreviation of the classes involved?

pyrogen
 
2005-09-28

here is the class with the issue...

the netstream is inited in another, and past into this class constructor, video loads fine, just the onMetaData duration loses scope within class

class VideoPlayerUI{

private var _net_stream;
private var _timeline:MovieClip;
private var _videoLinkage:String;
private var _videoRef:MovieClip;
private var _progressBarShell:MovieClip;
private var _progressBar:MovieClip;
private var _timerBar:MovieClip;
private var _stroke:MovieClip;
private var _myDur:Number;
private var _owner;
private var _loaded_interval:Number;
private static var _progressBar_X_offset:Number = 1;
private static var _playBtnOffset:Number = 15;


public function VideoPlayerUI( timeline:MovieClip , videoLinkage:String , ns){
    _net_stream = ns
     _timeline = timeline;
     _videoLinkage = videoLinkage;
     _net_stream._scope = this
     _net_stream.onMetaData =  this.onMetaData;
    // _myDur = undefined;
     init();

};


public function endSession():Void{
    _net_stream.clear();
    _net_stream.close();
    clearInterval(_loaded_interval);
    trace( " net stream is closed");

};

public function playVideo( obj:Object ):Void{
    endSession();

    _net_stream.play(obj);
    _loaded_interval = setInterval( this , "displayProgressBars", 100 );



};

private function init(){
    attachVideoClip();
    createLoaderBars();

};


private function onMetaData( obj:Object ):Void{

    _myDur = obj.duration;


    trace(_myDur +" is the duration of this clip : onMetaData"+arguments.callee);

};



private function attachVideoClip():Void{
    _videoRef = _timeline.attachMovie ( _videoLinkage , "_videoRef" ,   _timeline.getNextHighestDepth() );
    _videoRef.my_video.attachVideo( _net_stream );

};

private function createLoaderBars():Void{

    createProgressBarShell();
    createProgressBarBack();
    createProgressBar();
    createTimerBar();
};

private function createProgressBarShell():Void{

    _progressBarShell = _timeline.createEmptyMovieClip("progressBar_mc", _timeline.getNextHighestDepth());
    var progressBarX = _videoRef.my_video._x;
    var progressBarY = (_videoRef.my_video._y + _videoRef.my_video._height + _progressBar_X_offset);
    _progressBarShell._x = _videoRef.my_video._x+ _playBtnOffset;
    _progressBarShell._y = progressBarY;

};

private function createProgressBarBack():Void{

        _stroke = _progressBarShell.createEmptyMovieClip("stroke_mc", _progressBarShell.getNextHighestDepth());         
        _stroke. beginFill(0xcccccc);
        _stroke.moveTo(0, 0);
        _stroke.lineTo( _videoRef.my_video._width - _playBtnOffset , 0);
        _stroke.lineTo( _videoRef.my_video._width - _playBtnOffset, 10);
        _stroke.lineTo(0, 10);
        _stroke.lineTo(0, 0);
        _stroke.endFill();


};

private function createProgressBar():Void{

        _progressBar = _progressBarShell.createEmptyMovieClip("bar_mc", _progressBarShell.getNextHighestDepth());           
        _progressBar. beginFill(0xeeeeee);
        _progressBar.moveTo(0, 0);
        _progressBar.lineTo( _videoRef.my_video._width - _playBtnOffset , 0);
        _progressBar.lineTo( _videoRef.my_video._width - _playBtnOffset, 10);
        _progressBar.lineTo(0, 10);
        _progressBar.lineTo(0, 0);
        _progressBar.endFill();


};
private function createTimerBar():Void{

        _timerBar = _progressBarShell.createEmptyMovieClip("timer_mc", _progressBarShell.getNextHighestDepth());            
        _timerBar. beginFill(0xaeaaeaa);
        _timerBar.moveTo(0, 0);
        _timerBar.lineTo( _videoRef.my_video._width - _playBtnOffset , 0);
        _timerBar.lineTo( _videoRef.my_video._width - _playBtnOffset, 10);
        _timerBar.lineTo(0, 10);
        _timerBar.lineTo(0, 0);
        _timerBar.endFill();


};

private function displayProgressBars():Void {   


   var pctLoaded:Number = Math.round( _net_stream.bytesLoaded / _net_stream.bytesTotal * 100 );
   var curTime = Math.round( _net_stream.time  / _myDur * 100);

    _progressBar._xscale = pctLoaded;
   _timerBar._xscale = curTime;
  // trace(_myDur);

   if (curTime == 100) {
      // p_done = true;
      // p_play = false
      // pauses.inside.gotoAndStop(1);
      clearInterval( _loaded_interval );

   }

};

}

persist
 
2005-09-28

I see.

What happens to this trace?:

private function onMetaData( obj:Object ):Void{

    _myDur = obj.duration;

    trace(this+" "+this._scope);


    trace(_myDur +" is the duration of this clip : onMetaData"+arguments.callee);

};
pyrogen
 
2005-09-28

this:

30.941 is the duration of this clip : onMetaData[type Function]

persist
 
2005-09-28

wtf.

so the line trace(this+" "+this._scope); traces nothing?!

What about:

private function onMetaData( obj:Object ):Void{

    _myDur = obj.duration;

    trace(this+" THIS A TRACE "+this._scope);


    trace(_myDur +" is the duration of this clip : onMetaData"+arguments.callee);

};
pyrogen
 
2005-09-28

sorry, missed your inclusion

yeah i tried that before i get this:

Error /Volumes/slave/com/netStream/VideoPlayerUI.as: Line 60: There is no property with the name '_scope'. trace(this+" "+this._scope);

Total ActionScript Errors: 1 Reported Errors: 1

pyrogen
 
2005-09-28

oddly enough, "onMetaData" is not a member of the netStream class, weird huh?

persist
 
2005-09-28

There must be something unique happening. I don't work with FCS so I am shooting in the dark here with the netstream object. But you'd want that metadata for otehr stuff to so its frightening.

what happens if you do this:

public function VideoPlayerUI( timeline:MovieClip , videoLinkage:String , ns){ net_stream = ns timeline = timeline; _videoLinkage = videoLinkage; _netstream.parent = this _netstream.onMetaData = function(){ trace(this.parent); } init();

};

it may be required to use extends to allow netstream to carry a scope.... thinking...

persist
 
2005-09-28

Perhaps bypassing the compiler directives would work using an evaluation since it won't be able to check the intrinsic class list:

public function VideoPlayerUI( timeline:MovieClip , videoLinkage:String , ns){ net_stream = ns timeline = timeline; _videoLinkage = videoLinkage; _netstream["parent"] = this _netstream.onMetaData = function(){ trace(this.parent); } init();

};
pyrogen
 
2005-09-28

yep that did it, apparently the onMetaData must be called directly inside the constructor function....... and not passed to a class member... weird

public function VideoPlayerUI( timeline:MovieClip , videoLinkage:String , ns){
     _net_stream = ns
     _timeline = timeline;
     _videoLinkage = videoLinkage;

     _net_stream.parent = this
           _net_stream.onMetaData = function(obj){
            this.parent._myDur = obj.duration;
            trace(this.parent._myDur +" is the duration of this clip :   onMetaData"+arguments.callee);
            trace(this.parent);
     };

     init();

};
persist
 
2005-09-28

its the same as nested xml contructions.

Can you go with that?

pyrogen
 
2005-09-28

thanks man k

pyrogen
 
2005-09-28

yeah it works fine.

i just get thrown sometimes with as2 scope

thanks bro

persist
 
2005-09-28

everyone does. it takes some getting used to!

Welcome to the board by the way.

Your portfolio is incredible.

pyrogen
 
2005-09-28

thanks man k

i come here a lot to read, but just signed up

used to hang at were- here forums........ but ya know k

thanks for the kind words about our work

later man

destin

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

onMetaData // netstream // obj.duration losing scope with in an as2 class