dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Stop FLV playback in child when removing child (or at least silence audio)

  1. #1
    Senior Member
    Join Date
    Feb 2008
    Posts
    107

    Stop FLV playback in child when removing child (or at least silence audio)

    I'm working on a flash site with a number of different "states" (home, features, demo, etc.) each of which is a movie clip with its own actionscript, added as a child when requested, removed when the user chooses a new state.

    One of the states plays short FLV videos. The problem is, when switching away from that state to a different state, even though the child is removed, the current video apparently keeps playing as I can hear the audio continuing on.

    To demonstrate, the site is here. Click on "Demo", then play one of the videos and switch to a different state (home, features, whatever) while the video plays.

    I'm trying to call a function in the child to stop video playback (first checking whether the function exists before trying to call it). The checking part works, but the function call is giving me a "call to possibly undefined method" error when publishing. Probably because I'm calling it the wrong way.

    Here's the "remove child" code used after switching to a new state:

    Code:
    var child:DisplayObject;
    
    while(stateContainer.numChildren > 1)
    {
    	child = stateContainer.getChildAt(0);
    	if ('stopPlayback' in child)
    	{
    		trace('exists');
    		child.stopPlayback();
    	}
    	else
    	{
    		trace('does not exist');
    	}
    	
    	stateContainer.removeChildAt(0);
    }
    Can you tell me a better way to do this? I find it strange that it traces "exists" when the function exists, but still complains that child.stopPlayback() (might not) exist.
    Last edited by bunner bob; 11-09-2008 at 02:33 PM.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Before deleting you can use the stop() function of the videoplayer component.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Senior Member
    Join Date
    Feb 2008
    Posts
    107
    Quote Originally Posted by cancerinform
    Before deleting you can use the stop() function of the videoplayer component.
    Can you clarify? How would I do that? How do I address the player within the child? Internally in my child I address the player thus:
    movieChild.theVideo.stop();

    So I suppose I can say:
    child.movieChild.theVideo.stop();


    But I tried this and still get errors that the property "movieChild" is possibly undefined:

    Code:
    var child:DisplayObject;
    
    while(stateContainer.numChildren > 1)
    {
    	child = stateContainer.getChildAt(0);
    	if (child.hasOwnProperty('movieChild') && child.movieChild.hasOwnProperty('theVideo'))
    	{
    		trace('exists');
    		child.movieChild.theVideo.stop();
    	}
    	else
    	{
    		trace('does not exist');
    	}
    	
    	stateContainer.removeChildAt(0);
    }
    I just don't get why Flash is so ...stupid - I just checked that the property existed! The next statement is conditional on WHETHER the property exists! It's like getting a green light and then saying "but I don't know if there's really a green light".

    Sorry - if PHP (my primary language) was as convoluted as Actionscript I would have switched to farming a long time ago
    Last edited by bunner bob; 11-10-2008 at 02:41 PM.

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to use the name of the movieclip followed by the name of the videocomponent + the stop action.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Senior Member
    Join Date
    Feb 2008
    Posts
    107
    Yes...I understand that.

    "movieChild" is the name of the movieclip within the child. "theVideo" is the name of the video object.

    I tried removing the conditional but of course it fails just as miserably as before:
    Code:
    var child:DisplayObject;
    
    while(stateContainer.numChildren > 1)
    {
    	child = stateContainer.getChildAt(0);
    	child.movieChild.theVideo.stop();
    	
    	stateContainer.removeChildAt(0);
    }
    - possibly undefined property 'movieChild'

    What I need to say is "IF the child we are about to remove CONTAINS a movie clip called "movieChild", and if THAT movie clip contains "theVideo", THEN tell theVideo to stop."

    But I don't seem to be getting it.

  6. #6
    Senior Member
    Join Date
    Feb 2008
    Posts
    107
    Hmmm - nothing?

    Is this not possible?

    Check if a function is defined in a child? If it is, execute it?

    Or, check if a video is playing in a child. If it is, stop it? But the first option would work better for me...

  7. #7
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Do you have a videoobject or are you using the videocomponent?
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  8. #8
    Senior Member
    Join Date
    Feb 2008
    Posts
    107
    It's an instance of the videocomponent.

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