Link to home
Start Free TrialLog in
Avatar of pm2k
pm2k

asked on

Flash + ASP

I'm new in flash and I'm in the intermediate stage for ASP. My problems are:
- how do I retrieve image from database and display in flash?
- how do I return n number of record from database. Example: Select * from table1 where Nick = 'pm2k'; return 5 record and display it into flash?
- Can I do data grid in flash? How?
Pls explain in advance as I need to understand the concept, flow and script!
ASKER CERTIFIED SOLUTION
Avatar of kanary
kanary

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kanary
kanary

sorry if i didn't mention the comcept.

flash can retrieve data from external file like: asp, php, txt, xml and so on.

who does this work?

let's take the simplest example txt files:
the txt file should be on the form:
var1=data1&var2=data2&var3=data3 and so on.

so the flash file knows now that there are 3 variables and 3 values for these variables.

so like what i mensioned in the first question u should load these variables from the specified file like this

myData = new LoadVars();
myData.source = "test.asp";   // the sourse data file
myData.onLoad = function(){        
    img=this.imgpath;    
}
myData.load(myData.source);

now that variables are loaded and u should store their values in flash variables like in the onload function:

img=this.imgpath;  

//img is the flash variable
//this to refere to the variable path
//imgpath the variable name that u have pronted in the txt file

by now every variables u printed are now loaded in the flash file, and u can access them easily.

wana more details ?

kanary
here's another link to non-free macromedia flash data grid component

http://www.macromedia.com/software/dataconnection/
Avatar of pm2k

ASKER

Yes Indeed, I need more details
if possible do you mind explaning it in simple english?

myData = new LoadVars();
myData.source = "test.asp";
myData.onLoad = function(){        
    img=this.imgpath;    
}
myData.load(myData.source);

then u create an empty movie clip u sing this function:
createEmptyMovieClip("movie",1)
movie.load(img);

the code shown above is not clear enough for me to understand
and where's all the function?

For question 1, let say I already store the img in access using ASP, how do I retrieve it?


EXAMPLE:
FileID    FileName    FileSize    ContentType    BinaryData
1           a.jpg          67827      image/jpeg      .ong binary data
2           b.gif           753          image/gif          .ong binary data
.......and so on
*Pls note that the data type for BinaryData is OLE Object
hello again

concening storing images in the database. store another field in the database containing the image bath like:
FileID    FileName    FileSize    ContentType    BinaryData                 Filepath
1           a.jpg          67827      image/jpeg      .ong binary data         c:\a.jpg
2           b.gif           753          image/gif          .ong binary data         d:\b.jpg

so u retrieve the image path and send it to the flash file by printing the filepath.

2)

myData = new LoadVars();
myData.source = "test.asp";  
myData.onLoad = function(){        
   img=this.imgpath;    
}
myData.load(myData.source);

these bunch ofline are used to load the data from the source file. just copy and paste them in the first keyframe in ur flash file.

"test.asp" is the asp file that prints the image paths.
"img" now contains the image paths from the asp file.

just put thisline after the img=this.imgpath; line  
 
trace(img);

what output do u get?

Avatar of pm2k

ASKER

ok thanks kanary
but I have no time to test the code yet as it is very late at night now. I will test it and let you know tomorrow morning.
Anyway if I were to intergrate Flash and ASP isn't it I have to use loadVariables() to get or pass the value from flash to ASP and from ASP to flash?
If that is true I had try this

I created a form using flash with there input box; name, age, tel and 3 button; reset, submit and display.
the input box is for user to enter their information while the reset button is to reset the form and submit to pass the value to ASP page and from ASP the value will be saved in the database, and lastly the display button which will gotoAndStop(3) to display the value from database.

in the first frame i have the stop(); command

and in the submit button i have this script
on (release) {
      if (name eq "" or age eq "" or tel eq "") {
            stop();
      }
      else {
            loadVariablesNum ("add.asp", 0, "POST");
            gotoAndStop (2);
      }
}

and in the display button I have this script
on(release) {
                loadVariables("display.asp");
      gotoAndStop(3);
}


and so I get this error

Scene=Scene 1, Layer=Layer 1, Frame=1: Line 2: Wrong number of parameters; loadVariables requires between 2 and 3.
           loadVariables("display.asp");

any idea?
thanks again
Note that I will increase the point as much more question will be question
hello pm2k again,

if u increased the points to 500 i'll be ready to write a full documentation of Flash MX :))

there's a difference  in the buttons functionality.
the submit  button should send data to asp file then database
while the display button will get data from the database and asp file to be displayed in the flash file.

"loadvariablesnum" and "loadvariables" are used to load data from asp file or txt file.
while "geturl" is used to open a browser and u can add as many parameters to the page as u wish.

so in our example. when u press submit button, u wana send the 3 values of the text boxes, t1,t2,t3 which are txt1,txt2,txt3 like this:

on (release) {
    if (name eq "" or age eq "" or tel eq "") {
         stop();
    }
    else {
         getURL ("add.asp?t1=txt1&t2=txt2&t3=txt3","_blank");
         gotoAndStop (2);
    }

and in the asp page u request.querystring the variables like this:

text1=response.querystring("t1")
text2=response.querystring("t2")
text3=response.querystring("t3")



phew..., now for the display button
when pressed u wana get data from the asp file, thus using loadvariables or loadvariablesnum or using loadvars()

i prefered using my code above because it's error free, and guarentee that the data is fully loaded before u proceed (btw u get error from loadVariables("display.asp"); because it takes at least 2 parameters like this loadVariables("display.asp",_root.movie);

so on button display
on(release) {
     myData = new LoadVars();
     myData.source = "display.asp";  
     myData.onLoad = function(){        
     //get the data from the asp file as u wish    
  }
myData.load(myData.source);
gotoAndStop(3);
}


wana more details... u shouuld pay :))

Avatar of pm2k

ASKER

Hey thanks Kanary
If possible i will increase my points to 500 but unfortunely I have only 185 points left.
I was thinking what else and how much can you help me out, so maybe I can give you all my points. Just let me know
hello pm2k,

im ready for any question u like, jusy lay out and think, kanary will be beside u :), even if i don't know it, i'll search for and learn it for u.
u can c my profile to know what other tools and techniques im experienced in.

i can figure now that u have solved the above problem, right?

waiting ur questions.
Avatar of pm2k

ASKER

Well kanary, I really appriciated it! Yes I mean your help.
Indeed I just fixed my problem yesterday, but unfortunely I didn't use the first method you mention. Sorry about that as I really don't understand each statement. If I were to understand then it would be much more easier for me to use and apply, don't you agree that?

I have visited your history and found that you are not only good in Flash but also other language including .Net. That really impress me much. So I'm assuming you are good in visual basic and ASP too.

There's one thing that I'm always not clear with between Ms Access and MySQL. I once develop 2 internal system using ASP with Ms Access, and VB with Ms Access. Everything seems to be fine at that time. But later on I was requested to migrate the data from Ms Access to MySQL, and so I did. Then problem occur.

ASP Code (Example)
1.)
If not rs.EOF then
  rs.movefirst
  Do Until rs.EOF
    (...do something...)
    rs.movenext
  Loop
End If
This code works fine with Ms Access but after the migration to MySql, I always get error and so my solution was  to remove the rs.movefirst command. Why?

2.)
Sql = "Select * From table1;"
rs.open sql, "DSN=Data"
rs.AddNew
rs.fields("a") = request.form("a1")
rs.fields("b") = request.form("a2")
rs.fields("c") = request.form("a3")
rs.Update
rs.close
This code too works perfect with Ms Access but you know, after the MySQL stuff everything goes wrong and my solution was to change the Sql = "Insert into table1 (a, b, c) values (......................)" and remove the rs.AddNew till rs.update. Why? Anything wrong here?

Now back to flash
_root.txtmessage
is this statement correct?
I clicked on the debug button and it says not syntax error.
But when I test it doesn't response. How?
Avatar of pm2k

ASKER

New problem discovered:

My insert.asp code
<!-- include = "adovbs.inc" -->
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Demo"

Sql = "Select * From Table1;"

Set Rs = Server.CreateObject("ADODB.Connection")
Rs.Open Sql, oConn

Rs.AddNew
Rs.Fields("Name") = Request.Form.Item("inputname")
Rs.Fields("Age") = Request.Form.Item("inputage")
Rs.Update

Rs.Close
Set Rs = Nothing
oCOnn.Close
Set oConn = Nothing
%>
is there anything wrong? Hopefully not

My flash code
On the add button I have this script
on (release) {
      loadVariablesNum("insert.asp", 0, "POST");
anything wrong with this?
}

My problem is that I couldn't add the value to database
Note that I pass 2 value from flash to asp which is insertname and insertage
Oh ya why can't flash return any error msg while running?
Cause I'm not used to it whenever it doesn't show error whereby there is actually some error!
Avatar of pm2k

ASKER

I'm sorry but the Set Rs = Server.CreateObject("ADODB.Connection") is actually Set Rs = Server.CreateObject("ADODB.Recordset")
and do i need to clear my temp folder everytime i make changes in flash?
Avatar of pm2k

ASKER

Ok now that I have change the code to
<!-- include = "adovbs.inc" -->
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Demo"

'Sql = "Select * From Table1;"
Sql = "Insert into Table1 (Name, Age) values ('" & Request.Form.Item("inputname") & "', '" & Request.Form.Item("inputage") & "');"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open Sql, oConn

'Rs.AddNew
'Rs.Fields("Name") = Request.Form.Item("inputname")
'Rs.Fields("Age") = Request.Form.Item("inputage")
'Rs.Update

Rs.Close
Set Rs = Nothing
oCOnn.Close
Set oConn = Nothing
%>
it work!
Well it seems that insert into table1 ......... values ...............
work better than the addnew and update
so mind to tell me when to use addnew and when to use update?
tq
Avatar of pm2k

ASKER

I just wanna know why I can't use the rs.addnew and rs.update on certain scenario?
wooow, toooo many question to be solved.


1) _root.txtmessage ??
do u have a variable called txtmessage and u wana output it?
if u wana check a variable value, just type trace(txtmessage)

2) concerning
 on (release) {
    loadVariablesNum("insert.asp", 0, "POST");
anything wrong with this?
}

i really described it in full details above, so plzz go slowly through it.

3) does table1 has any required fields that should be entered instead of name and age?
maybe addnew should be used if u r at the end of the RS to add another new row, but in insert into is an sql statement that knows what it should do.
advice: now u r using mysql which is not microsoft product, so avoid any command that it used with access and use the international sql language instead.
Avatar of pm2k

ASKER

Ok allow me to explain to see if I understand what you mean kanary. Thanks for your patient.
so trace() is actually something similar to <%=var%> in asp which display the value hold by the variable right?
If I'm correct, what does the _root.txtmessage do? What does the _root mean? Nop I don't have the varible called txtmessage, so how and where do I declare that?
Avatar of pm2k

ASKER

Sorry again I left out another question.
Earlier you suggested that I store the path of an image instead of storing the whole image into database.
That was a good idea instead,
but how do I

(in ASP)
-get the path of the image
-how to display via image (example displaying a value is <%=Rs("field")%>, but what about path? Is it something like path=C:\image.jpg?) Please give in full code.

(in flash)
-img=this.imgpath is to get the path and display rite what about passing the path to ASP?
1)
trace in flash = response.write in asp

if u have a variable called myvar in asp u type: response.write (myvar)
also if u have a variable in flash u type: trace(myvar); then press ctrl+enter to test the movie.
a new white window opens displaying the value of your variable.

2)
u have many levels in ur stage, like: _root, _this,..

_root mean the very first main stage at the first frame.
so if u have a textbox named "t" for example and placed it in the first frame of the stage, u can refer to that text anywhere in the flash movie using this notation:
_root.t=anything



3) image path
just a string. it's soo simple. in ur asp page when the user upload the image file, grap the loaction of thie image at this time. it look like this: imgpath="C:\myimage.jpg"
and then store this string into the database.

and in flash, after u print this string path in asp,  u type in flash img=this.imgpath, then imgpath will contain the image path string. put this path into the load function like this

createEmptyMovieClip("movie",1)
movie.load(imgpath);

and u will c it immediately.


i think u need to go through some flash tutorials, as it's not right to learn flash by trial and error.
here's a magnificant 2 links:
www.flash-kit.com
www.actionscript.org


plzz pm2k add the other 185 points to the question because the rule here is that no more than one question should be asked, so u should increase the points accordingly.
thx.
Avatar of pm2k

ASKER

Alright kanary,
I'm really sorry as I'm a new comer and as you can see this is my second question posted. In fact I didn't get my answer for the first question, can I actually get back my points?
Anyway I'm looking forward for your help again Kanary!
Thanks again!
first of all thnk u for ur honesty for giving the points.

second, i have soled ur question in pure details. and im ready to explain more

what esle u wana me to discuss?
Avatar of pm2k

ASKER

Ok one last question, I promise
I have created a dynamic text box which is actually used to display image from database to it. So if my database only store one image then everything is fine.
But I had thoughts that the database will increase sooner or later and since I only created one dynamic text box so I guess it can only hold one image at a time.
My question is whether there's anyway to overcome this? Maybe it will auto-create, or something like  the following code:
While not Rs.EOF
response.write "OK<BR>"
rs.movenext
Loop?
Any idea here?
Pls note that I can't affort to create n numbers of dynamic text box to standby!
ok, simply add a new record to the table containing noof pictures.

then send this number to the flash.
and loop on this number to create as many dynamic text boxed as this number
then fill in the text boxes :))