programming behavioral experiments in flash session 1 of 3 intro to web programming, php, and flash...

32
Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Upload: christopher-gordon

Post on 30-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Programming Behavioral Experiments in Flash

Session 1 of 3Intro to Web Programming, PhP, and Flash

January 29th – Jeff Galak (NYU)

Page 2: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 2

Agenda for the Week

• Session 1: Thursday, January 29th (2-4pm): Intro to Web Programming, PhP, and

Flash

• Session 2: Friday, January 30th (10-12pm): Building Your First Flash Experiment

• Session 3: Friday, January 30th (3-5pm): Advanced Topics if Flash(Sounds, Videos, and Real Time Ratings)

Page 3: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 3

Agenda for Today

• Why Flash?

• Software requirements.

• How to run experiments and collect data.

• Components of a Flash experiment.

• A brief discussion on PhP.

• Your first look at Flash

Page 4: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 4

Three Programming Options (maybe 4)

Page 5: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 5

Why is Flash best?

• Almost entirely cut + paste• Web based

– Ubiquitous “Flash Player”

• Massive support infrastructure online– Tech-support = Google– For really tough problems:

www.experts-exchange.com

• I’m pre-writing 99% of all your future programs.

Page 6: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 6

What software will you need?

• Flash…duh.– Anything after version 7 is fine.– CS4 is ideal (it’s the latest and what I use).

• Text editing software for PhP– Notepad works just fine.– I use EditPad Pro because it makes life easier.

• FTP Program– Use whatever your school IT dept recommends.– I use FileZilla because it works with almost every FTP

standard (including SFTP/SSH)

Page 7: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 7

What you need to run a Flash Experiment

• Access to a web server with:– PhP 4 or 5 support– Your school should have this– USC:??

• If you want to get fancy, you can store the data in a database (MySQL). – Ask me about this off-line

Page 8: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 8

The Flash Experiment Infrastructure

URL

PhP Parser

Calls Flash (SWF) File

Flash SendsData

Converts Raw Data into CSV

Ss goes to website

Page 9: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 9

6 Files For Every Program

Don’t get scared…it’s not that complicated

1. Flash .fla file- This is the file you program in.

2. Flash .swf file- This is the file that you upload to the web server.- It is automatically created by Flash

Page 10: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 10

6 Files For Every Program

3. Condition file: .txt

- This is just a place holder file that helps with assigning conditions

4. PhP: .php execution file

- This file acts like an .html file and runs your flash program (.swf).

- It assigns conditions (more later)

Page 11: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 11

6 Files For Every Program

5. PhP: .php debriefing file- This is where you include the debreifing for your experiments (it can be blank…but has to exist).

6. PhP: .php parser- This is a program I wrote that converts Flash data into a .csv data file- You never have to touch this file…just make sure it’s there.

Page 12: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 12

Setting up Your Program

• Use a simple naming convention.• Here’s mine:

– Pick a simple name (workshopfiles)– Use that to name the folder– Every file (except the parser) shares the same name

• workshopfiles.fla• workshopfiles.swf• workshopfiles.txt• workshopfiles.php• workshopfilesdebrief.php

Page 13: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 13

Let’s Start with PhP

• You do not need to know how to understand everything!

• I have put comments throughout the entire file.

• There are only a few lines of code that really matter.

Page 14: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 14

First a Note about Conditions

• PhP and Flash don’t understand what a 2x2 is.• But they understand numbers.• So if you have, say, a:

2 (Name: Jeff, Not-Jeff) x 3 (Awesomeness: Low, Medium, High)

you rewrite the conditions as:

1 = Jeff + Low 4 = Not-Jeff+ Low2 = Jeff + Medium 5 = Not-Jeff + Medium3 = Jeff + High 6 = Not-Jeff + High

Page 15: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 15

workshopfiles.php

You only care about two lines:

$experimentname = "workshopfiles";- defines the name of the experiment

$numofconditions = 6;- defines the number of conditions

Ignore the rest

Voilà! You learned php.

Page 16: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 16

First Look at Flash

Page 17: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 17

Tools

Timeline

Layers

Stage

Parameters

Library

Zoom

Page 18: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 18

A Note on Layers

Always have 4 layers (at least) in this order

1. Actionscript (keep ALL scripts in here)

2. Text (all text related stuff here)

3. Button (all interactive stuff here)

4. Outline (all background stuff here)

Page 19: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 19

How to Insert a Frame/Screen

This is the most annoying part of flash:

1. Highlight entire column of frames BEFORE the place you want to insert a new one.

- Do this by clicking on the top one, then holding down SHIFT and clicking on the bottom one.

2. Hit F5 to insert new

frame to the right

of the original frame

Page 20: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 20

How to Insert a Frame/Screen Cont…

If you want to copy and paste an existing frame (you almost always do), again select the ENTIRE column of frames and right click on them…then select “Copy Frames”

Page 21: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 21

How to Insert a Frame/Screen Cont…

Then again highlight the ENTIRE new column and right click on the new column and select “Paste Frames”

Page 22: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 22

A Note on Parameters for Text Boxes

Static Text: never changesDynamic Text: can be modified via actionscriptInput Text: used to get collect user responses (and can be modified via actionscript)

Instance Name: This is what you name your object. You refer to this name when you want to do things like make it invisible.

Var: is the name of a variable that is associated with the content of the text box. This is one of the easier ways to manipulate what is in the box via actionscript.

Multiline vs. Single Line: Self explanatory

If selected makes the text html formatted. VERY useful for manipulating font/style/color.

If selected puts a shadow box behind text. Great for “Input Text”

Page 23: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 23

Different Types of Inputs

• 7/9 point single item scale• 7/9 point multi-item scale (on same page)• Slider scale• Choices• Text (short and long)• Sum to 100%

• 7/9 point multi-item scale on different pages (randomizing order)

Page 24: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 24

How to Test Your Program

• CTRL + ENTER: Run entire program• CTRL + ALT + ENTER: Run current scene

• SHIFT + ENTER: Compile program

• trace!!– Sends text to the “output” window– Only used for debugging– VERY useful

Page 25: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 25

Your Three Best Friends

1. Copy + Paste– Demo

2. Google– Aka. Flash Community

3. Experts-Exchange.com– Saved me many many times

Page 26: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 26

ActionScript Basics - Variables

• Variables can be declared, but don’t have to be. Examples:

var myVariable = 10;

myArray = new Array();

• Avoid reserved names– If a variable “turns blue,” change it.– E.g. “new”, “array”, “data”, “time”, etc…

Page 27: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 27

ActionScript Basics – Variables Tricks

• How to convert a number stored as a string to a number that you can work with:– Easy: multiply by 1– If you have:

myVariable = “1”;

and you want to have a new variable which is equal to myVariable + 5 :

newVariable = myVariable * 1 + 5;

Page 28: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 28

ActionScript Basics – Data Flow

• Some data comes in from the initial php file (workshopfiles.php): – ip, condition, date_start, time_start

• All data (including the initial data) must then be stored in a single variable in Flash (datastring)– This is done using the storedata fuction– This function ONLY works when the entire

program is run (not just a single scene).

Page 29: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 29

ActionScript Basics – Storing Data

• Data is stored using the function “storedata”– How to store the value in the variable “name”:– storedata(“name”, name)

– Both can be “hard coded” or variables.– MAKE SURE THAT “COLUMN NAMES” ARE

UNIQUE!!

Name of column in data file Value to store

Page 30: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 30

ActionScript Basics – Conditionals

if(person==“jeff”) {text = “The person is Jeff”;}

else {text = “The person is not Jeff”;}

2 equal signs for checking “sameness”

Parentheses around the conditional Brackets around

action

Does this if the conditional fails

Page 31: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 31

Homework

1. Install software

2. Try and upload the existing files to your webserver and see if everything works– Make sure to check permissions (CHMOD 755 (or

777) works well)…ask me for help

3. Take any simple questionnaire you have and try to turn it into a program (at least 2 conditions)– If you can’t get the web version to work just yet, try

and get it to work locally (e.g. with CTRL+ENTER)– If you don’t have a questionnaire, I will give you one

Page 32: Programming Behavioral Experiments in Flash Session 1 of 3 Intro to Web Programming, PhP, and Flash January 29 th – Jeff Galak (NYU)

Session 1 - 01/29/2009 32

Next Session

Friday, January 30th (10-12pm):

Building Your First Flash Experiment

• Create a complete experiment– Create php file– Create flash program– Test– Upload everything