Click to See Complete Forum and Search --> : Flash coding help needed please


benrussell
01-29-2009, 04:25 PM
I have a website that I am altering at
http://www.christiancountyvideo.com/crisp/biggerscreen/index2.html.

This is what I would like to do:
When on my website, click on the wedding portfolio tab to open a video gallery. I would like this video gallery to work where you click on the image button to open a corresponding video in the video player.

I have code that makes this "video gallery" (2.swf) work on its own.
Here's the link to this gallery on its own:
http://www.christiancountyvideo.com/crisp/biggerscreen/2.swf

The following code is what I used to trigger the movie. I placed it individually inside each "button".

on (release, releaseOutside) {
var hitpart = this._name.toString().split("Thumb");
_parent._parent.cThumb = Number(hitpart[1]);
if(_parent._parent.cThumb!=_parent._parent.oThumb){
_parent._parent.gotoAndPlay("Change");
}
_root.ns.play("segway.flv");
}

Here's the problem. Why will this code not work when 2.swf is loaded in though index.swf? :( I hope that makes sense. I'm using Macromedia Flash MX2004 (Actionscript 2.0) for the coding of the flash.

If I'm not posting at the proper place, do you have anywhere you would reccomend? Thank you very much for the help!


P.S. If you need the code for the video player, here it is. I gathered it from the tutorials at gotoandlearn.com.
var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);

ns.setBufferTime(5);

ns.onStatus = function(info) {
if(info.code == "NetStream.Buffer.Full") {
bufferClip._visible = false;
}
if(info.code == "NetStream.Buffer.Empty") {
bufferClip._visible = true;
}
if(info.code == "NetStream.Play.Stop") {
ns.seek(0);
}
}

theVideo.attachVideo(ns);

ns.play("http://www.captivatingtimephotography.com/embed/TrashTheDressComplete.flv");

rewindButton.onRelease = function() {
ns.seek(0);
}

playButton.onRelease = function() {
ns.pause();
}

var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;
var duration:Number;

ns["onMetaData"] = function(obj) {
duration = obj.duration;
}

function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * 158;
loader.scrub._x = ns.time / duration * 158;
}

var scrubInterval;

loader.scrub.onPress = function() {
clearInterval(videoInterval);
scrubInterval = setInterval(scrubit,10);
this.startDrag(false,0,this._y,158,this._y);
}

loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
clearInterval(scrubInterval);
videoInterval = setInterval(videoStatus,100);
this.stopDrag();
}

function scrubit() {
ns.seek(Math.floor((loader.scrub._x/158)*duration));
}

var theMenu:ContextMenu = new ContextMenu();
theMenu.hideBuiltInItems();
_root.menu = theMenu;

var i1:ContextMenuItem = new ContextMenuItem(":::::Video Controls :::::",trace);
theMenu.customItems[0] = i1;

var i2:ContextMenuItem = new ContextMenuItem("Play / Pause Video",pauseIt,true);
theMenu.customItems[1] = i2;

var i3:ContextMenuItem = new ContextMenuItem("Replay Video",replayIt);
theMenu.customItems[2] = i3;

var i4:ContextMenuItem = new ContextMenuItem("Copyright 2009 Christian County Video",trace,true);
theMenu.customItems[3] = i4;

function pauseIt() {
ns.pause();
}

function replayIt() {
ns.seek(0);
}

Ben Russell

Eye for Video
01-29-2009, 07:57 PM
Hey Ben,
First I'd like to get a little more background info.
In your first bit of code you have a line
_root.ns.play("segway.flv");
When I directly download that .flv, its a movie about a man riding around on a Segway. Does that have anything to do with your movies? Or was that part of the sample code and you did a rename or something?
Anyway, it seems that when index2.html loads, you have the one version of "Trash my Dress" on autoplay. Is that correct? And that is the desired effect?
Are the nav buttons on the left jumping the timeline to a different spot on the main timeline, so then we click "Portfolio" we would see 2.swf load into a movie clip in some other frame in the main .swf called "index.swf"? Or is 2.swf being loaded some other way?
One thing I noticed was that the first video does not stop playing when you go to 2.swf. Then 2 starts playing so that both are running at the same time.
I guess I don't understand how you are using the thumbs in 2.swf to switch from one video to another. The only call for video that I see is
ns.play("http://www.captivatingtimephotography.com/embed/TrashTheDressComplete.flv");
Far as I know there are at least two ways to accomplish loading the next video. One method is to "push" the urls from an xml file into an array and choose whatever index number you want to play the various videos. Or, you place a series of movie clips in different frames, use loadMovie to bring in a .swf or whatever. What is the method you are trying to use to create or call the various urls to the different videos?
I only see that one call for video and the buttons are having no effect for me. Is that the problem or should they work when viewing 2.swf directly?
gotoandlearn is a great place for tuts and I often recommend them. Without more info, I'm not sure why this didn't work for you.
Here are a couple of example of using the 2 methods of creating playlists that I mentioned. First one uses ns and an xml array:
http://www.cidigitalmedia.com/video.html
This second one uses jumping to different frames in the timeline to load a .swf, which can display either video or photos in the same space on the page. That way there's no need to set up a photo display page and then another seperate page for videos.
http://www.lavendergrowers.org/chronicle.html
The video frames just use
ns.play
while the photo slide shows frame use
loadMovie
to load a .swf which is reading an xml array.
Perhaps with a little more info we can help you get this straightened out.
Best wishes,
Eye for Video
www.cidigitalmedia.com

benrussell
01-29-2009, 08:53 PM
Eye for video,

When I directly download that .flv, its a movie about a man riding around on a Segway. Does that have anything to do with your movies?
Sorry, no. I threw in some rendered videos so I had something to play with currently. My current website has been using WMV videos and I plan to switch over to flash videos.

When index2.html loads "Trash my Dress" is on autoplay. Is that is the desired effect?
At this point yes, unless you have some recomendations. :p I realize that due to a long load time for the website the music plays through my opening credits, but I thought that would be okay. Do you disagree>?

One thing I noticed was that the first video does not stop playing when you go to 2.swf
Yes. Do you know the code that I can put in there so the video stops playing when you navigate away from 1.swf? It would be very helpful. It would also help to have that command on for when users navigate away from 2.swf.

What is the method you are trying to use to create or call the various urls to the different videos?
I would prefer the 2nd method that you suggested -- "...jumping to different frames in the timeline to load a .swf, which can display either video or photos in the same space on the page." Actually, http://www.lavendergrowers.org/chronicle.html is very similar to what I wanted. I planned to have a scrollbar (eventually) on the 2.swf page with thumbnail buttons (and text) that would link to different videos in the player.

Let me know if this helps straighten things out, and thank you very much for the quick response and help! :D

Ben

Eye for Video
01-29-2009, 10:35 PM
"Do you disagree?"
Well I’m still humming your tune (can’t get it out of my head now), but in my opinion it needs a little work. Fixing the double audio problem would be a big help, but rarely is the use of audio on Web site loading ever mentioned when reviewing Best Web Practices. However, yours is a Multimedia Web site. When I do sites for bands, people expect MUSIC! In your case I think a few adjustments could satisfy most viewers. Start the video and music as you do now, but include a better mute button (very clearly marked). I searched around for something that looked a little like a mute button and finally clicked it. It stopped the music but also the video. Then on click again, nothing happens. I’ll attach a simple .flv player with controls and status bar. Here is the AS2 for the mute button, maybe you can adapt it.
//-------Sound Controls--------//
this.createEmptyMovieClip("sound_mc",this.getNextHighestDepth());
sound_mc.attachAudio(ns);

var videoSound:Sound = new Sound(sound_mc);

mute_btn.onRelease = function() {
if (videoSound.getVolume() > 0) {
videoSound.setVolume(0);
}
else
{
videoSound.setVolume(100);
}
}
" Do you know the code that I can put in there so the video stops..."
Dang, not off the top of my head. Once you start the ns, ….forgot how to turn it off. If you are using xml arrays, when you move to another video, that ns takes over. But you are moving to another .swf, which leaves the first ns still running, thus, the problem. One way around that with arrays is to call for a non-existing ns. Maybe you could adapt your method so that when you jump to another frame, there is code in the first frame or two which calls a fake video:
ns.play("fake.flv");
then plays right through to call the real video in the 3 or 4th frame (with a stop(); at the end of that section).
I’d suggest that you work to incorporate xml to populate the playlist. Create a swf which uses a xml feed playlist as your 2.swf. Then you could still incorporate that .swf into your main timelinewith a loadMovie, which would bring the complete 2.swf into your main timeline, but still retain all the xml playlist ability.
Sorry if this sounds confusing but I’m trying to watch “Rudy” at the same time! Take this projects in steps and we can walk you through it.
I'll attach a simple video player with controls that is only looking for one ns with a name "video1.flv". To test, put into the same folder as your video and rename that video "video1.flv".
Best wishes,
EfV

benrussell
01-30-2009, 09:52 AM
I got the mute button working! Thanks for your code, as I found Lee Brimelow's tutorial rather confusing. (He started in the middle and assumed I knew how to do what he did.)

Next step: stopping the video when exiting the flv page
I'll do some forum searching to see if I can find any more info on this.

Final Step: Playing the videos when thumbnail buttons are clicked
The only reason I wasn't sure about the xml playlist is because I didn't want a text playlist to the side of the video screen. I didn't think it looked as cool or fun as I would like.

Thanks for the help!
Ben

Eye for Video
01-30-2009, 08:29 PM
So have you worked out the "getting to stop" issue?
You might try adding this to your button which moves you to the next page:
netStream.seek(0)
netStream.pause();
I was trying to duplicate the two videos playing at the same time but my jumping to next frame section always worked...first video stopped, second started.
You must be using two seperate player, small one on home page, large one on other.
As far as xml playlist goes, you can still use thumbs instead of just text, as with the "Chronicle" playlist.
Good luck,
EfV

benrussell
01-31-2009, 09:28 AM
I tried the code you suggested and had no results. There are two possible reasons, but let me keep this simple and change the subject.:rolleyes:

Instead is there a code I can add to the main video player that pauses the video on a mouse clicking event? (Because I guess the only mouse clicking event on this page would be to watch another movie or to load another page.)

//-------Pause on Mouse Event--------//
function mouseDownHandler(event:MouseEvent): {
ns.pause();
}

I tried to find the right type of coding, but the above gives me errors.

If you need the current code on my video player, it is below. Thanks again!
//-------GoToAndLearn.com Video Player--------//
var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);

//-------Buffer Start--------//
ns.setBufferTime(15);

ns.onStatus = function(info) {
if(info.code == "NetStream.Buffer.Full") {
bufferClip._visible = false;
}
if(info.code == "NetStream.Buffer.Empty") {
bufferClip._visible = true;
}
if(info.code == "NetStream.Play.Stop") {
ns.seek(0);
}
}
//-------Buffer End--------//

theVideo.attachVideo(ns);

ns.play("http://www.captivatingtimephotography.com/embed/TrashTheDressComplete.flv");
ns.pause();

//-------Video Player Controls--------//

rewindButton.onRelease = function() {
ns.seek(0);
}

playButton.onRelease = function() {
ns.pause();
}

//-------Scrubber Bar--------//

var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;
var duration:Number;

ns["onMetaData"] = function(obj) {
duration = obj.duration;
}

function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * 350;
loader.scrub._x = ns.time / duration * 350;
}

var scrubInterval;

loader.scrub.onPress = function() {
clearInterval(videoInterval);
scrubInterval = setInterval(scrubit,10);
this.startDrag(false,0,this._y,350,this._y);
}

loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
clearInterval(scrubInterval);
videoInterval = setInterval(videoStatus,100);
this.stopDrag();
}

function scrubit() {
ns.seek(Math.floor((loader.scrub._x/350)*duration));
}

//-------Right Click Menu--------//

var theMenu:ContextMenu = new ContextMenu();
theMenu.hideBuiltInItems();
_root.menu = theMenu;

var i1:ContextMenuItem = new ContextMenuItem(":::::Video Controls :::::",trace);
theMenu.customItems[0] = i1;

var i2:ContextMenuItem = new ContextMenuItem("Play / Pause Video",pauseIt,true);
theMenu.customItems[1] = i2;

var i3:ContextMenuItem = new ContextMenuItem("Replay Video",replayIt);
theMenu.customItems[2] = i3;

var i4:ContextMenuItem = new ContextMenuItem("Copyright 2009 Christian County Video",trace,true);
theMenu.customItems[3] = i4;

function pauseIt() {
ns.pause();
}

function replayIt() {
ns.seek(0);
}

//-------Sound Controls--------//
this.createEmptyMovieClip("sound_mc",this.getNextHighestDepth());
sound_mc.attachAudio(ns);

var videoSound:Sound = new Sound(sound_mc);

muteButton.onRelease = function() {
if (videoSound.getVolume() > 0) {
videoSound.setVolume(0);
}
else
{
videoSound.setVolume(100);
}
}


Ben

Eye for Video
01-31-2009, 10:34 AM
OK, got it figured out. Whatever you are using as the "next" button, needs the code to pause the ns, like this:
next_btn.onRelease = function() {
ns.pause();
gotoAndPlay(2);
}
adapt the name and the frame number as needed.
Here is how I tested this. A video player in frame one plays your "Trash this dress" video. Clicking a simple "Next" button pauses the ns and jumps the timeline to frame two. Video stops and I had a simple non video animation play for a few frames. Then the "Next" button was coded to jump to frame 31 were a new ns was created and correctly played a second video. The coding for that "Next" button is same as above but jumps to frame one. Works great every time I try it.
EfV

benrussell
02-02-2009, 09:09 AM
I tried you code on the individual buttons with no success. I then tried it in the main actions section with the video player code -- no success there either.

I tried to mix it up with the original code, the one that worked separately from the index.swf. I placed it on the button and had no success. I also placed it in the action code with the video player code and had no success either.

on (release, releaseOutside) {
var hitpart = this._name.toString().split("Thumb");
_parent._parent.cThumb = Number(hitpart[1]);
if(_parent._parent.cThumb!=_parent._parent.oThumb){
_parent._parent.gotoAndPlay("Change");
}
_root.ns.play("segway.flv");
}

This code seems to trigger the video player when placed on the buttons of 2.swf. But when 2.swf is placed within index.swf, it doesn't work. Is there anything extra we can do to it to make it work? I know that it would be much cleaner to have this code in the main action section, but for some reason I couldn't call on the button to work from there (thumbnails.Thumb1.Button1.onRelease....)

Thank you very much for the help and patience!
Ben

Eye for Video
02-02-2009, 10:06 AM
To be honest, I can't make heads or tails out of the code shown above. It's really unclear to me just how your timeline is laid out and how you are jumping from one section to another. So just for my review, when you click the wedding portfolio button, you are jumping to another frame in the main timeline? Once there the wedding portfolio section will start to play? Is all of that included in 2.swf...but it seems there is a page transition and then 2.swf is displayed. Do the buttons on 2.swf work for you, that is they will jump from one video to another? Because I only see and hear the first video and the thumbs do not seem to work?
If the object is to jump to another section of the timeline and start another video, how about doing this test. Create a simple rectangle, convert to mc, give it an instance name of next_btn, and add this code to your main code, not on the button.
next_btn.onRelease = function() {
ns.pause();
gotoAndPlay(2);
}adjust the frame to fit your timeline. Does it jump to that frame? Does the ns pause?
I'll attach a second sample player to illustrate jumping from one section of the timeline to another and then starting a second video. Put in a folder with a "video1" and a "video2". The player will easily jump from one to another. It uses just a simple rectangle button, but that could just as easily be a thumbnail, a menu button or whatever.
Good luck,
EfV

benrussell
02-04-2009, 11:01 AM
Okay, I tried your code:
next_btn.onRelease = function() {
ns.pause();
gotoAndPlay(2);
}

I don't know why, but it didn't work. I drew out the rectangle, converted it to the next_btn, added the code to the main action section, and put the file a folder with two flv files named video1 and video 2. But no success. The video didn't even pause.

I attempted to use your "cidm_simple_vid_player_dbl.fla" file, but Macromedia Flash MX 2004 wouldn't open it. Any ideas?

Let's try this. Can I give you a copy of all 6 of my .fla files to see if they make sense? I zipped them up and the filesize is 1.2 meg, so it's too big for this forum, but here's a link on my website:
http://www.christiancountyvideo.com/crisp/test/CCVideo.zip

Thank you again for all you help.

Ben

Eye for Video
02-04-2009, 12:21 PM
Message received. I'll try to take a look at the files when I can...kinda busy right now. My file was a Flash 8 file so it won't open in MX. In the meantime, here's a MX version that you can play with.
EfV

benrussell
03-04-2009, 11:25 AM
Okay, so I put this project WAAAAY back on the backburner and finally pulled it out this morning. It seems the break did me good.

Firstly, my buttons and the movie that contained them did not have instance names. That is one reason why they didn't work.

Secondly, I changed the code a bit, instead of doing gotoandplay I closed the stream and started it over again on the push of every button! Wa La! It worked!

Here's the code:

Thumbnails.Thumb7.onRelease = function() {
ns.close();
ns.play("http://www.christiancountyvideo.com/Crisp/BiggerScreen/segway.flv");

Here's the link (http://www.christiancountyvideo.com/Crisp/BiggerScreen/index2.html)

Obviously you still have to pause the first movie so it doesn't conflict with the others on tab 2 (wedding portfolio). But tab 2 (wedding portfolio) works with the buttons now!

Now, if only I can get the videos to close when I click onto other tabs (wedding videos, wedding portfolio, wedding investment, about us, contact us.) I'm assuming I can add
ns.close(); somewhere with the tab names. We'll see.