Solved

Loading movies from db

Posted on 2004-04-13
17
312 Views
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
0
Comment
Question by:Shroom42
  • 7
  • 5
  • 3
17 Comments
 
LVL 2

Accepted Solution

by:
hansblix earned 250 total points
Comment Utility
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_vars.sendAndLoad("loadfromDB.php",movie_receive_vars);
movie_receive_vars.onLoad = function(success)
{
   if (success)
   {
      //If PHP returns a variable named movietobeloaded...
       trace("A variable returned by PHP = " + this.movietobeloaded);
       createEmptyMovieclip("movieholder_mc",100);
       movieholder_mc.loadMovie(this.movietobeloaded);
   }
}

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

Hope that helps :)
-H

----------------
http://www.quillem.com
0
 

Author Comment

by:Shroom42
Comment Utility
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
0
 
LVL 22

Assisted Solution

by:rascalpants
rascalpants earned 250 total points
Comment Utility
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(){
  if(success){
    _root.memberID = myData.memberID;
    _root.Fname = myData.Fname;
    _root.Lname = myData.Lname;
    _root.photoName = myData.photoName;
  } else {
    trace("error");
  }

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




rp
0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
and as far as loading multiple movies, you should only need to replicate the code above a few times...


rp
0
 

Author Comment

by:Shroom42
Comment Utility
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.

Cheers
0
 

Author Comment

by:Shroom42
Comment Utility
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)
0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
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&email=bob@aol.com&

- 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(){
  if(success){
    _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 {
    trace("error");
  }

};
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...


rp



 
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Shroom42
Comment Utility
>>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!

Thanks

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

Expert Comment

by:rascalpants
Comment Utility
Okay...

it seems we have to collect ourselves again...

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

rp
0
 

Author Comment

by:Shroom42
Comment Utility
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

0
 
LVL 2

Expert Comment

by:hansblix
Comment Utility
Shrrom42,

     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..
-H

----------------
http://www.quillem.com
0
 

Author Comment

by:Shroom42
Comment Utility
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
0
 
LVL 2

Expert Comment

by:hansblix
Comment Utility
Hi,

   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:
------------------
http://www.actionscript.org
http://www.kirupa.com
-------------------
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?

-H
---------------
http://www.quillem.com
0
 

Author Comment

by:Shroom42
Comment Utility
Thanks,

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!!)
0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
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...


rp
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now