Creating the Polling Tool 2

Download Report

Transcript Creating the Polling Tool 2

Polling Tool Part 2
Action Script and Flash
CIS 254
Review from Last Class
• SQL Table
– INTpoll
• PHP Files
– Connect PHP
– Add Polls
– Load Poll Data
– Vote For
Using the Polling Tool
• Get pool.zip from
www.digitalfabrications.com
• Open Flash Poll.fla
Project Layers
•
•
•
•
•
CoverChart
Graphs
Cover Booths
Outline
Text
•
•
•
•
•
•
Voting Booth
Forms
Thinking
Functions
Notes
Actions
Functions Layer
• Functions - This is what controls the whole movie.
• Function AddPolls(): Populates Drop Down Menu with
Poll Listings and then allows
• A user to select from that list.
function AddPolls() {
for (i=0; i<NumPolls; i++) {
var pollName
= eval("PollName"+i);
var pollID
= eval("PollID"+i);
PollSelect.addItem(pollName, pollID);
}
Change Handler
• Set ChangeHandler
PollSelect.setChangeHandler("SelectPoll")
;
_root.Status = "Select a Poll: Please take
some time to answer our survey - You can
only Vote once.";
}
Select Poll Function
• Function SelectPoll(): Tells the movie what to do when a user has
selected a
• Poll. Then loads the corresponding data for that Poll.
function SelectPoll(){
PollName = PollSelect.getSelectedItem().label;
PollID = PollSelect.getSelectedItem().data;
_root.Status = "Loading information for <b>"+PollName+"</b>";
_root.Go = "";
_root.Thinking.gotoAndPlay(2);
_root.CoverChart.gotoAndStop(1);
loadVariables(PathToPHP+"LoadPollData.php?PollID="+PollID,
_root);
}
Set Poll Function
•
Function setPollData(): Just dynamically sets the Radio Buttons with the current
selection choices from the database.
function setPollData() {
radioGroup.setChangeHandler("vote");
CheckBox1.setLabel(Selection1);
CheckBox1.setData("Votes1");
CheckBox2.setLabel(Selection2);
CheckBox2.setData("Votes2");
CheckBox3.setLabel(Selection3);
CheckBox3.setData("Votes3");
CheckBox4.setLabel(Selection4);
CheckBox4.setData("Votes4");
QuestionNew = Question;
_root.CoverBooth.gotoAndStop(2);
_root.Status = "You can now Vote for <b>"+PollName+"</b> Category";
voteButton.setClickHandler("voteNow");
}
Vote Now Function
•
Function voteNow(): This is what actually sends the users choice to the
database and increments the total votes for that selection by 1.
function voteNow() {
if (radioGroup.getValue() ne "") {
_root.Go = "";
_root.Thinking.gotoAndPlay(2);
_root.CoverBooth.gotoAndStop(1);
Status = "Thank you for you vote - We are currently checking to see if
you have already voted - and updating";
loadVariables(PathToPHP+"VoteFor.php?PollID="+PollID+"&Vote="+r
adioGroup.getValue(), _root);
} else {
_root.Status = "Please Select a Category to vote for";
}
}
Select Chart Function (1)
• Function createChart(): This creates the Charts
assigns values for the title and x and y values.
function createChart() {
• Set Chart Titles - You can also set other
properties here if you feel like it.
myBarChart.setChartTitle("Results");
myPieChart.setChartTitle("Results");
Select Chart (2)
• Set Data Provider
• The Selection variables are from an earlier database query - the
updated values where just returned.
var pollData = new DataProviderClass();
var items = new Array({label: Selection1+"("+VotesNew1+")", value:
VotesNew1}, {label: Selection2+"("+VotesNew2+")", value:
VotesNew2}, {label: Selection3+"("+VotesNew3+")", value:
VotesNew3}, {label: Selection4+"("+VotesNew4+")", value:
VotesNew4});
for (var i = 0; i < items.length; i++) {
pollData.addItem(items[i]);
}
Chart Function (3)
• Assign Data Provider to Bar and Pie Chart.
myBarChart.setDataProvider(pollData);
myPieChart.setDataProvider(pollData);
myBarChart.sortItemsBy("value", "DESC");
myPieChart.sortItemsBy("value", "DESC");
}
Actions Layer
• This line sets the Top status - aka name of Charting app.
TopStatus = "Voting Booth: Please take some time to answer are
survey.";
• Path to PHP files - Leave this as Blank if the Flash movie is in the
same directory as the PHP scripts. If your PHP files are in a different
folder then your Movie - change this path to that folder
PathToPHP = "";
_root.Go = "";
_root.Status = "Loading current Question and Poll Data...";
_root.Thinking.gotoAndPlay(2);
loadVariables(PathToPHP+"AddPolls.php", _root);
stop();