Framework on which to build - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Framework on which to build

Description:

Creates new LoadVars objects and initialises one to hold a couple of variables ... LoadVars with PHP: http://www.sephiroth.it/tutorials/flashPHP/loadVars ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 13
Provided by: gawainSoc
Category:

less

Transcript and Presenter's Notes

Title: Framework on which to build


1
Framework on which to build
  • Quick review of LoadVars and event handling
  • The example user interface
  • Some example Flash code
  • Discussion of the framework
  • Actions for you to carry out
  • Further reading

2
LoadVars example ActionScript
  • Creates new LoadVars objects and initialises one
    to hold a couple of variables - This is what we
    will send to the server
  • var lvOutputLoadVars new LoadVars()
  • var lvInputLoadVars new LoadVars()
  • lvOutput.myStatus "Info text here"
  • lvOutput.myData "123456"
  • Odd looking way of creating variables!
  • Variables are treated as custom properties of
    objects

3
LoadVars example ActionScript
  • When we receive the response from the server,
    just print it to the debugging console
  • lvInput.onLoad function(bOkayBoolean)
  • if(bOkay true)
  • trace("Reply1 was " lvInput.myVar1)
  • trace("Reply2 was " lvInput.myVar2)
  • trace("Reply3 was " lvInput.someOtherInfo)
  • else trace("No reply from server script.")
  • Sends our message to a script and get ready for a
    response
  • lvOutput.sendAndLoad("myScript.php", lvInput,
    "POST")

4
LoadVars example PHP
  • Expects form-like data. We will reply through
    variables
  • lt?php// reads data POSTed from a form
  • myInput1 _POST('myStatus')
  • myInput2 _POST('myData')

5
LoadVars example PHP
  • Sends some data back to the client
  • // ends up doing simple text output
  • echo "myVar1myInput1"
  • echo "myVar2myInput2"
  • echo "someOtherInfo12345678"
  • This automatically creates the attributes
    lvInput.myVar1, lvInput.myVar2 and
    lvInput.someOtherInfo when Flash receives the
    data
  • Very easy to use!

6
The example interface
7
The example user interface
  • Each button calls the same script but sends a
    different command
  • Each button triggers this sequence
  • Set variables in lvOutput
  • Set lvInputs onLoad handler to point to a
    function
  • Call the PHP script and asks for data to go to
    lvInput
  • Then, when the PHP has run (some time later)
  • Data comes back from the server and gets put into
    lvInput
  • Our onLoad function runs
  • It reads the variables out of lvInput and puts
    them in a label

8
Some Flash ActionScript
  • info_btn.onPress function ()
  • fnTalkToServer("getInfo", "1", "",
    fnBasicCallBack)
  • feedback_txt.text "Get Info(1) ..."
  • function fnTalkToServer(sStatusString,
    sData1String, sData2String, fnCallBackFunction)
    Void
  • lvOutput.ntStatus sStatus
  • lvOutput.ntData1 sData1
  • lvOutput.ntData2 sData2
  • lvInput.onLoad fnCallBack
  • lvOutput.sendAndLoad("newTechExample.php",
    lvInput, "POST")

9
Some Flash ActionScript
  • function fnBasicCallBack(bOkayBoolean)Void
  • if (bOkay true)
  • / trace("Got server reply")
  • trace(lvInput.ntStatus)
  • trace(lvInput.ntData1)
  • trace(lvInput.ntData2)
  • /
  • feedback_txt.text lvInput.ntData1
  • else
  • feedback_txt.text "Could not load data from
    server"

10
A framework for re-use
  • The example gives information on one item only
  • It does not connect to a database
  • It does not allow for stored user feedback
  • But it does show how you can interact with a
    server from Flash
  • It demonstrates how to pass simple commands and
    get simple replies
  • It implements one function the image loader,
    this could be any data (e.g. MP3 sound for the
    MP3 player example)

11
Actions for you
  • Get a copy of the framework
  • Put the copy into your server area
  • Get it working
  • Only when it is working
  • Make a new copy
  • Modify it to provide different information
  • Make the system show a different image
  • Then think about what you need for your choice of
    assignment topic

12
Further Reading
  • Client/Server Frequently Asked Questionshttp//w
    ww.faqs.org/faqs/client-server-faq/index.html
  • LoadVars with PHP http//www.sephiroth.it/tutoria
    ls/flashPHP/loadVars/
  • ActionScripts.org, LoadVariables and LoadVars
    Objects http//www.actionscripts.org/tutorials/b
    eginner/loadVariables_and_loadVars/index.shtml
Write a Comment
User Comments (0)
About PowerShow.com