Loading movies from db

Posted on 2004-04-13
Last Modified: 2011-08-18
I know nothing/little about actionscript.

I need to load 3 movies into my main movie using the details from a DB (MySQL).

I have the movie urls and a value I want to pass to a javascript function dependant upon which movie is playing when they click on the movie.

Any help offered would be most gratefully accepted
Question by:Shroom42
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3

Accepted Solution

hansblix earned 250 total points
ID: 10821772
a)A loadvars call from Flash to a PHP script
b)A PHP script that loads data from the DB
c)PHP script "echos" a bunch of name value pairs
d)Flash receives it and loads appropriate movieclip

//Flash side of things:
movie_vars = new LoadVars();
movie_receive_vars = new LoadVars();
movie_vars.anyvariableyouwanttosendtoPHP = "sendmethismovie";
movie_receive_vars.onLoad = function(success)
   if (success)
      //If PHP returns a variable named movietobeloaded...
       trace("A variable returned by PHP = " + this.movietobeloaded);

//This is all off the top of my head.. so my apologies for any syntax errors :P

Hope that helps :)


Author Comment

ID: 10825792
Thanks for the input Hansblix.

I need it all to be done in flash and the detail to passed out from Flash when the movie is clicked to a Javascript function.
This will be done from an ASP page (although I thought this would not be relevent as such). I wish only to load the movie URL of 3 movies into the 'master' movie and then play the 3 sequentially. I do not want another external call as once the focus has moved from the movie I do not want it to go back unless it is clicked.

I know this can be done, but started to get a headache reading the help files.

Thanks in anticipation
LVL 22

Assisted Solution

rascalpants earned 250 total points
ID: 10835253
big H has the right method, so just augment that idea and use ASP code instead...  something like this would be what you need:

the below code is being used in another current quesiton...  so please just place your own variable where needed...


sql_query1 = "SELECT * FROM tblMembers WHERE MemberID=" & memberID  
' put recordset code here using  rs1

sql_query2 = "SELECT * FROM tblGallery WHERE MemberID=" & memberID

' put recordset code here using  rs2

Response.Write "memberID="& memberID &"&Fname="& rs1.Fields("Fname") &"&Lname="& rs1.Fields("Lname") &"&photoName="& rs2.Fields("photoName") &"&"


then in your SWF use this LoadVars code:

myData = new LoadVars();
myData.memberID = _root.theMembersIDgoesHere;
myData.onLoad = function(){
    _root.memberID = myData.memberID;
    _root.Fname = myData.Fname;
    _root.Lname = myData.Lname;
    _root.photoName = myData.photoName;
  } else {

myData.sendAndLoad("/design-gallery.asp", myData, "GET");

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

LVL 22

Expert Comment

ID: 10835265
and as far as loading multiple movies, you should only need to replicate the code above a few times...


Author Comment

ID: 10837726
Thanks for the input but you are assuming I know too much.

Please could you spell it out a bit more for me.  I sort of get it, but am having trouble putting it into my setup.

If I passed the movie 3 variables -> filename 1,2+3
and wanted 1 variable back - filename(whatever clicked)

Do I put all the code in frame 1? How does it know where to put the movie? I just get movie 3 being played.


Author Comment

ID: 10837748
Although rather than pass the filenames could I not have Flash use as SQL statement to pull the data in by querying a MySQL table? (As this is where they are stored)
LVL 22

Expert Comment

ID: 10842345
Flash cannot directly connect with a DB unless you are using Flash Remoting...  which I assume you are not...  you need to use a server side language...

so you need to follow these steps...

- use a server side page(ASP in your case) to call MS SQL and return a query
- then you structure your ASP code to output the variables you want passed into name/value pairs:

  variable1=value1&variable2=value2&variable3=value3&   or  name=Bob&phone=555-5555&

- then you use the LoadVars() method to load the data into your movie(SWF)   ////see above code
- once the variables are loaded into the movie you can use loadMovie() to pull in the proper movies/jpegs/mp3s

it would be best to place the loadMovie() code in the onLoad function of LoadVars()

something like this maybe:

myData = new LoadVars();
myData.onLoad = function(){
    _root.movieClipName1.loadMovie(myData.filename1, _root);
    _root.movieClipName1._x = 10;
    _root.movieClipName1._y = 10;
    _root.movieClipName2.loadMovie(myData.filename2, _root);
    _root.movieClipName2._x = 50;
    _root.movieClipName2._y = 50;
    _root.movieClipName3.loadMovie(myData.filename3, _root);
    _root.movieClipName3._x = 100;
    _root.movieClipName3._y = 100;

  } else {

myData.sendAndLoad("fileName.asp", myData, "POST");

the above code assume you have 3 movieclips that will load the movie into them...  so you just need to create 3 blank movieclips and give them instance names...  then you place those instance names in the above code where they say movieClipName...

let me know if you need more info...



Author Comment

ID: 10845571
>>the above code assume you have 3 movieclips that will load the movie into them...  so you just need to create 3 blank movieclips and give them instance names...  then you place those instance names in the above code where they say movieClipName...

I am not sure I am doing this correctly. Could you talk me through each step.

Sorry, but I am a complete noob.  I will increase the points for your effort though!


PS Will the movies play one after the other?
How do I output a different value dependant on which movie is playing?
LVL 22

Expert Comment

ID: 10845679

it seems we have to collect ourselves again...

what exactly are you trying to do...  not too many details...  just he basics


Author Comment

ID: 10846447
Thanks for your time rp, I appreciate it very much! You have the right idea, I am just not very proficient!

OK. from step 1

1) Pass 3 filenames to an empty flash movie
2) Load these 3 movies and play one after the other and loop round.
3) If the movie is clicked on pass a variable out to another asp file dependant on which of the 3 loaded movies is playing at the time (this can be the filename in step1)

each time the movie loads the 3 movies loaded will be different.

I have some idea but it is probably best if you assume no knowledge as I am still learning!

Thanks once again


Expert Comment

ID: 10852054

     While I like to help people understand concepts or debugs their scripts, you are asking for a prepared solution, which I am hesitant to give. However, I will point out the step by step method of doing this in theory...

Just a few things first:
As RascalPants has rightly pointed out, Flash cannot access DB's directly (by itself).. It will need a server side script such as PHP or ASP. To pass and load variables the optimal method is to use the LoadVars object to communicate with an external script. Data is passed between the script and Flash as name-value pairs [no arrays etc.].

a)You will have a main swf file which will create a Movieclip that loads random movie from your server. Let's call this movieclip "loader_mc".

b)Before loading anything into loader_mc, we need the swf names from the database. So we need to use the loadVars object as above to load these names from the ASP file. The ASP file can typically output the 3 filenames in 2 different ways:
   1) movienum=3&movie1=a.swf&movie2=b.swf&movie3=c.swf
   2) movies=a.swf|||b.swf|||c.swf

When 1 is loaded you will need to first check movienum, and run a for-loop from 1 to movienum and retrieve the filenames.

When 2 is loaded, you will need to use the String.split method to split the filenames into respective indices of an array.

c)So now that you have your movienames, you will need to use loader_mc to load the appropriate swf file. To handle the sequential and looping playback of the swfs, you will need to use an onEnterFrame or a setInterval to continuously check loader_mc, to see if it has reached it's final frame [see MovieClip._currentFrame and MovieClip._totalFrames], and load the appropriate swf.

d)A click action for loader_mc will use another LoadVars to send the data to another ASP file which does whatever it needs to do..

Hope that is of some help..


Author Comment

ID: 10852405
Thanks again Hansblix.

Whilst a prepared solution would be nice ;-)  I would much prefer to learn how to do it myself!

You have given me the pointer I needed in order to look up anything I dont understand now, before I was somewhat lost.

A couple of questions though

1) does all the code go into frame1 or do I need to make the code for movie 2 go into another frame?
2) rascalpants mentioned instance names which you dont. This confuses me somewhat.

I had hoped to teach myself but I think I need to get myself a decent book on the subject (I will have to wait til payday tho!). Could you recommend one?

I did not realise actionscript would be so tricky!

Thanks one and all once more

Expert Comment

ID: 10856063

   Glad to hear that you would like to learn :P

Answers to your questions:

1) Since you are going to be loading the movieclips 'sequentially', you should just be able to use just 1 Movieclip which loads the movies one by one.. If you would like pretty transitions between movieclips then you might need more than 1.. While you should be able to do everything in 1 frame, I suggest that you split up the actionscript into 2 frames - first for loading the data, and the second for the actual loading of the movieclips..

2)I did mention instance names : 'loader_mc' is an instance name :) In my case I just used one movieclip which loads the 3 external movieclips 1 by 1.. RP decided (probably for simplicity's sake) to use 3 movieclips, which load the corresponding external movieclip - hence 3 instance names..

3)Yes, I don't think this is really a beginner's project if this is your first go at some AS :)
Rather than a book, I'd suggest you check out some tute sites, and press F1 regularly :)
Good Tute Sites:
Flash comes with it's own tutorials as well :)
If need be, get a book to progress once you gain some momentum. Are you using MX/MX2004?


Author Comment

ID: 10857224

I am using MX2004.  This would certainly not be a project of choice for a first go with AS but I had an ASP+Javascript page which did this but it kept taking the focus everytime the movie changed and so I thought that if I could load one flash movie that once the focus had passed on that it would not be grabbed again!

Rather than wash my hands of the project at this point, I decided to try and do the right thing and deliver something that worked!  And now my head hurts!

I have not had a chance to go through this yet as I have to fit it around other bits too, but I will endevour to try mon/tues evening.

Thanks once again for your help, I think I would have gone mental without it!  Just by reading your comments I feel that I have got a chance! (albeit an uphill struggle!!)
LVL 22

Expert Comment

ID: 10870196
not only for simplicity, but for future Actionscript development, I think you should load the movies into seperate movieclips...

if in the future, you want to have better control over each individual movie, then this would be the best way to do that...

what is the status of this project/question anyway?   I have been on vacation for a while and need an update...


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question