ASP + flash drop-down list (displaying images)

Source: Internet
Author: User

---------------------------------------------------------
<! -- # Include file = "conn. asp" -->
<%
Dim rsBiClass, outBigClass, outBigClassID
SQL = "select * from bigclass"
Set rsBigClass = server. CreateObject ("adodb. recordset ")
RsBigClass. open SQL, conn, 1, 1
Do while not rsBigClass. eof
OutBigClass = outBigClass & rsBigClass ("bigClass ")&"/"
OutBigClassID = outBigClassID & rsBigClass ("id ")&"/"
RsBigClass. movenext
Loop
Response. write ("outBigClass =" & outBigClass &"&")
Response. write ("outBigClassID =" & outBigClassID)
RsBigClass. close
Set BigClass = nothing
Conn. close
Set conn = nothing
%>
------------------------------------------------------
Save as readBigClass. asp <! -- # Include file = "conn. asp" -->
<%
Dim bigid, outSmallClass
Bigid = request. Form ("bigid ")
SQL = "select * from smallclass where bigid =" & bigid
Set rsSmallClass = server. CreateObject ("adodb. recordset ")
RsSmallClass. open SQL, conn, 3, 3
Do while not rsSmallClass. eof
OutSmallClass = outSmallClass & rsSmallClass ("smallclass ")&"/"
OutSmallClassPic = outSmallClassPic & rsSmallClass ("pic ")&"/"
RsSmallClass. movenext
Loop
Response. write ("outSmallClass =" & outSmallClass &"&")
Response. write ("outSmallClassID =" & outSmallClassPic)

RsSmallClass. close
Set rsSmallClass = nothing
Conn. close
Set conn = nothing
%>

Save it as readSmallClass. asp. I believe everyone can understand this ASP code. If you don't understand it, follow the frame and I will note it again.
--------------------------------------------------------------------------------
Now we can program in flash.
Find a drop-down list from the component and pull it into two scene formats. Name it myBigCmb and mySmaCmb respectively.
Write in the first frame:
System. useCodepage = true;
Var readBigL = new LoadVars (); // defines a LoaVars class object.
ReadBigL. load ("readBigClass. asp"); // load the readBigClass. asp page.
ReadBigL. onLoad = function (su ){
If (su ){
// ReadBigClass. asp loaded successfully
_ Root. gotoAndPlay (2 );
}
};
Stop ();
----------------------------------------------------------------------------
// Most of the content of the second frame has been used in the previous frame. It is nothing more than retrieving data from the database and putting the data into the defined array.
Frame 2:
Var bigClassA = new Array ();
Var bigClassIDA = new Array ();
For (I = 0; I <readBigL. outBigClass. length; I ++ ){
BigClassA = readBigL. outBigClass. split ("/", I );
BigClassIDA = readBigL. outBigClassID. split ("/", I );
}
For (j = 0; j <bigClassA. length; j ++) {// This is to put the category into the first drop-down list.
MyBigCmb. addItem ({label: bigClassA [j], data: bigClassIDA [j]}); // add data to the drop-down list, if you are not very clear, please refer to the component tutorial to learn it :)
}
IntiItem = myBigCmb. selectedItem. data; // This is the value that is initially displayed in the first drop-down list. so. if the flash is run, the second drop-down list will have no value.
GetSmallClass (intiItem );
// GetSmallClass () is a UDF. I will introduce it later. its function is to obtain the values of small classes corresponding to the selected category from the database. return the value to the second drop-down list.
// -------- Change ----------------------------------------
My = {};
My. change = function (cmb) {// This is the change event in the main category, that is, the first drop-down list.
Bigidf = cmb.tar get. selectedItem. data; // obtain the data value of the selected option in the first drop-down list.
GetSmallClass (bigidf );
// Call the UDF here. in this case, when the category changes, the corresponding small class value is retrieved from the database, and the value is then assigned to the second drop-down list.
};
// -------- Obtain the small class value from the database -----------------
Function getSmallClass (bigidf) var smallClassSV = new LoadVars ();
Var smallClassLV = new LoadVars ();
SmallClassSV. bigid = bigidf;
// Note that smallClassSV. bigid is used for variable writing. If the preceding smallClassSV is not added, the value of bigid will not be uploaded to the loaded ASP file.
SmallClassSV. sendAndLoad ("readSmallClass. asp", smallClassLV, "POST ");
// This sendAndLoad method is used to load the page. At the same time, the result is returned to the smallClassLV class.
SmallClassLV. onLoad = function (su ){
// Note that the onLoad event here is smallClassLV, rather than smallClassSV (when I first started using this method, I got stuck here for a long time)
If (su ){
_ Global. smallClass = smallClassLV. outSmallClass;
_ Global. smallClassID = smallClassLV. outSmallClassID;
SetSmallClass ();
// Another custom function is called here. This function is used to assign values to the second drop-down list and put the data received by smallClassLV into the second drop-down list.
} Else {
Aa. text = "data connection failed ";
  }
};
}
// ---- Put the small class value in the drop-down list ----------------------------------------
Function setSmallClass () {// This is the custom function. It is used to assign values to the small class (the second drop-down list).
// If you can understand the above, you may not need to explain the following ....
Var smallClass = _ global. smallClass;
Var smallClassID = _ global. smallClassID;
Var smallClassA = new Array ();
Var smallClassIDA = new Array ();
For (I = 0; I <smallClass. length; I ++ ){
SmallClassA = smallClass. split ("/", I );
SmallClassIDA = smallClassID. split ("/", I );
}
MySmaCmb. removeAll ();
// Clear the original values in the drop-down list.
For (j = 0; j <smallClassA. length; j ++ ){
MySmaCmb. addItem ({label: smallClassA [j], data: smallClassIDA [j]});
}
Picname = mySmaCmb. selectedItem. data; // This is the initial value for obtaining the second drop-down list.
Loadpic (picname); // call the function for loading images.
}
// --------- Small class change -------------------------------
Mys = {};
Mys. change = function (cmb ){
// This is a small change event
Sid = cmb.tar get. selectedItem. data; // when the selected value (that is, selectedItem) of the small class changes, the selected data value of the small class is obtained.
Loadpic (sid); // call the value of the loaded image. If the value of a small image changes, the corresponding displayed image also needs to be changed.
};
// ------------- Load external image ------------------------------
Function loadpic (picname) {// This is the function for loading images.
_ Root. createEmptyMovieClip ("picmc", 0); // create a blank video clip.
_ Root. picmc. _ x = 200;
_ Root. picmc. _ y = 100; // set the position of the blank film.
_ Root. picmc. loadMovie (picname); // load the image. Note that the picname in it is uploaded when this function is called (actually the image name)
}
MyBigCmb. addEventListener ("change", my); // add the change event in the drop-down list.
MySmaCmb. addEventListener ("change", mys );
Stop ();
// OK, have a try!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.