Avatar of Dier02
Dier02
Flag for Australia asked on

Load FLV via external script

I want to be able to specify which FLV file gets loaded into which viewer (i have four on a page with instances named 1,2,3,4.) and I want to be able to do that using an external .as file.
Adobe Flash

Avatar of undefined
Last Comment
blue-genie

8/22/2022 - Mon
blue-genie

do you mean an external as file as in one you import (AS2) or do you mean you want to write a class to do it (AS3)
Dier02

ASKER
As in one you import - so that it is referenced as an #include
blue-genie

typically you can just cut your code out of your fla, stick it in an as file and call the methods from the AS file.
put your #include right it the beginning.
then publish and see what it complains about and address them from there.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Dier02

ASKER
Any idea how to write the include?

blue-genie

#include whateveryourasfileiscalled.as

Dier02

ASKER
no, what I meant was how to write the script for adding an flv to your player.  The idea is that you can modify the script externally to assign a different flv file to that player.  And then place the #include in your movie. (Sorry, I confused this with the #include comment).
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
blue-genie

okay i think i'm confused.
let's assume you have a FLVPlayback component on the stage called player.

then in  your as file you can  just create a method


function setPath(str:String) {
 
// Create a NetConnection object
var my_nc:NetConnection = new NetConnection();
// Create a local streaming connection
my_nc.connect(null);
// Create a NetStream object and define an onStatus() function
var my_ns:NetStream = new NetStream(my_nc);
 
my_video.attachVideo(my_ns);
// Set the buffer time
my_ns.setBufferTime(5);
// Begin playing the FLV file
my_ns.play(str);
 
}
 
alternatively if you're playing local flv files you can set the contentPath of player with str instead of doing the netStream.
 
then you just call the function 
setPath("http://myserver/video.flv"); 

Open in new window

Dier02

ASKER
The FLV files are local files.  
blue-genie

ok so  you use contentPath so -does that answer your question?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Dier02

ASKER
So the external .as simply says - setPath(myVideo.flv) if it is in the same folder as the SWF and I write the #include.external.as in the SWF?
Dier02

ASKER
What would the external .as say?  It is the .as that runs the movie I assume?
Dier02

ASKER
Is this right?

onClipEvent (load) {setPath("video.flv");
}

The SWF, the Include.as (above) and the flv are all in the same folder.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
blue-genie

a .as file simply means your code sits in an external file instead of on the timeline somewhere - when you compile your movie - the code gets compiled into the swf anyway. it's just easier to manage in large projects using external .as files.

ok so on Frame 1 of your movie, include your .as file

#include whateveritscalled.as

then what are you using to trigger the setPath?
if you want to call it immediately you can just say

setPath("video.flv");

but you must change setPath to say yourflvplaybackname.contentPath = str;




Dier02

ASKER
Got everything except the last comment - lets say my flv is called video.flv would I write video.contentPath=str; ? This would go on the timeline?  I don't add anything to the parameters of the movie component?
Dier02

ASKER
1000: Unable to make connection to server or to find FLV on server

the external .as below
onClipEvent (load) {video.flv.contentPath = str;
}

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
blue-genie

no. you now have the setPath function included in your fla file right?
who are you putting the onClipEventLoad code onto?

i meant that you must change your setPath if you're using a local file - see snippet.

i'm not sure what you're trying to achieve but I'm assuming you're doing this because you have one FLVPlayback component that you want to use to show different videos - so why are you putting it onClipEvent?

rather just call the function and set the contentPath each time to what you want it to be.
function setPath(str:String) {
 
video.flv.contentPath = str;
 
}

Open in new window

Dier02

ASKER
This is in AS2 if that makes a difference
Dier02

ASKER
I placed the code on frame one of the movie and just got:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 16: Statement must appear within on/onClipEvent handler
     function setPath(str:String) {

Total ActionScript Errors: 1        Reported Errors: 1
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dier02

ASKER
I need to know three things:

1. Does any code go into the parameters of the FLVPlayback MC?

2. What do I put into the external.as

3. the only code in the fla is the #include

Is this correct?
ASKER CERTIFIED SOLUTION
blue-genie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dier02

ASKER
I did exact;y as you said.  I put the code into the external.as and only the #include in the fla - and thats the message I recieved - that it needed anon/onClipEvent handler error
Dier02

ASKER
the only code in the fla is the #include - for now yes - assuming there is no other stuff you're doing but you still have to call the function setPath inside the as file - so like i said in an earlier post you must decide when and how you are wanting to change which flv is playing inside your FLVPLayback component." but wasn't that the whole purpose of this exercise - to work out a way of changing which local flv is playing in the component using an external.as file??
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
blue-genie

ok i don't know how else to explain this to you.
where is your #include filename.as code exactly?

>> but wasn't that the whole purpose of this exercise - to work out a way of changing which local flv is playing in the component using an external.as file??

a flvplayback has a property called contentPath - which means what video do you want me to show.
so now you have a function called setPath(blah);
where blah is the name of the video you want to show   - so whats the problem?
maybe i should leave you to it and you can get someone else to assist you.
otherwise upload your fla file (just the fla - add a .txt extention).

up to you.
Dier02

ASKER
OK - it was on the component instead of frame 1 so thats been changed.
Now - the external .as is as follows:

function setPath(str:String) {
 
video.flv.contentPath = str;
 
} where video is the actual name of the flv.  However I am getting the following when I click on the play button of the component when I play the movie.

1000: Unable to make connection to server or to find FLV on server
blue-genie

ok zip up your stuff and i'll have a look, i can't see what it is you're doing otherwise.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dier02

ASKER
Came up with a different approach.  Decided to place the flv player on frames with a main page/ frame with the movie names and a link to each.
blue-genie

if you want you can still upload the stuff so i can have a look for next time.