First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
Search tutorials
Author: James Greenhalgh | Website: http://www.odslinux.com

Onto the Flash

Well now that all the scary PHP and db stuff are done, the Flash is a breeze. I'm not going to go too in depth into the Flash, as the functionality is very basic. I will give a brief frame step by step though.

Frame 1:
The Ask Leaphy button gathers the question ('q') and how many results to return ('r') and sends those variables to the PHP.

Ask Leaphy Button Actionscript
On (Release, Key: )
   If (q ne "")
      Comment: Checks if the Maximum Results is a number, if not it returns 10.
      If (int(r) = 0)
         Set Variable: "r" = "10"
      End If
      Comment: Loads the variables into the PHP.
      Load Variables ("http://www.yourwebsite.com/dgssearch/search.php", "", vars=POST)
      Go to and Play ("Asking")
   End If
End On


Note: Don't forget to change the address from http://www.yourwebsite.com/dgssearch/search.php in the .fla


Frame 2:
The editable text fields become non editable and I changed the colour for effect. The loop begins waiting for the response from the PHP script. If the PHP has finished executing and a match was recorded, it goes to the 'Possible Answers' frame. If there is no match, then it proceeds to the 'Sorry' frame.

Frame 2 Actionscript
Comment: Check if the query returned any matches. If
((linksloaded eq "yes") and (link1 >  0))
   Set Variable: "i" = "1"
   Set Variable: "links" = ""
   Loop While (eval("link"&i) ne "")
      Set Variable: "links" = links & eval("word"&i)  & Newline
      Set Variable: "i" = i+1
   End Loop
   Go to and Stop ("Possible Answers")
Else If ((linksloaded eq "yes") and (link1 = 0))
   Go to and Stop ("Sorry")
End If


Frames 3-7:
This is the first loop to keep our playhead moving while the search.php is executing.

Frame 8:
This is the 'Sorry' frame. It is where the playhead goes to if no matches are made with the DB, it includes an Ask Again button that wipes all the variables and returns you to the first frame.

Frame 9:
This is the 'Possible Answers' frame. After the PHP has returned the variables, a text field is populated with the possible answers. This frame also includes 10 instances of the invisible button. These invisible buttons call the goToLink script, passing the buttonNumber variable that is different for each button.

Invisible Button Actionscript (buttonNumber changes for each button)
On (Release)
   Set Variable: "buttonNumber" = 1
   Call ("goToLink")
End On
goToLink Actionscript
Set Variable: "id" = eval("link"&(links.scroll-1+buttonNumber))
If (id ne "")
   Begin Tell Target ("/Cache")
      Set Variable: "id" = /:id
      Load Variables ("http://www.yourserver.com/dgssearch/answer.php", "", vars=POST)
      Go to and Play (2)
   End Tell Target
   Go to and Play ("Answer")
End If


The only really tricky part of this Actionscript is perhaps the first line. To get the id, Flash evaluates what the link## variable is equal to, where ## is the buttonNumber variable sent from the invisible button + the scroll.

Note: I use this technique often when working with sending and recieving variables from backends. By using an Invisible Movie Clip Instance named 'Cache' to store my data and post my variables to, I can control all the variables being sent back and forth to the PHP/Perl a lot easier.


Frame 10:
This playhead begins to loop as the PHP seeks out the answer to the question. Once the answer is loaded it moves to the 'Answer Loaded' frame.

Frame 10 Actionscript
Comment: PHP loads the answer from the db
If (Cache:answerloaded)
   Set Variable: "theTruth" = Cache:theTruth
   Begin Tell Target ("/Cache")
      Go to and Stop (1)
   End Tell Target
   Go to and Stop ("Answer Loaded")
End If


Frames 11-15:
This is the second loop to keep our playhead moving while the answer.php is executing.

Frame 16:
This is the 'Answer Loaded' frame. Simply a display for the answer that gets returned from the database query. It also includes buttons to either go back to the possible questions or GO Back and use a different keyword entirely.

Frame 17:
gotoLink Actionscript (as described earlier) Again, don't forget to change the server address in the Actionscript.
» Level Advanced

Added: 2001-02-19
Rating: 8.04 Votes: 48
(10 being the highest)
» Author
I work for a Canadian software company as a logisitics director. We provide custom configured Linux distributions. In my spare time I sleep.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.