If you have your own tutorials or open source and would like to share your Director knowledge please send them to info@shocksites.com. We will review them, post it and give full credit to the developer.
Current Open Source and Tutorials

Download the Open Source Here

Creating a profile with setPref and getPef
Provided by Troy Hipolito and Johan Verhoeven

Create a property list from text fields and graphics then make an external profile. No Xtras needed.

Note: This shockwave piece will save your profile. Next time you enter this page from the same computer it will remember you.

Contents
1. Description
2. Sample
3. Profile Process

Description
The information for avatar will be set in a profile. This profile will be an external text file that contains information about the user and the avatar. Such information would be:

Name:
Email:
Password:
HairType:
HeadType:
ShirtType:
PantsType:
ShoesType:

The “Name, Email, and Password could be pretty much anything. The other items for the avatar would be picked graphically.

Each time the user would launch this desktop app, Director would read the external text file and build the avatar accordingly. First of all if the profile was not made then it goes to a screen that requires them to create one.

The user would fill out the info and select the type of avatar desired. Also in the future there may be several simulated avatar movements. This would happen by swapping out graphics and using a few “if then statements” to make sure we were swapping out the correct avatar body parts.

The setPref and getPref would be used to make the text file (it would be located in the “Prefs” folder). Basically we will be using this to read and write the text file, which is the profile. The getPref and setPref lingo commands work differently in the development environment and the final out put.

In the development environment (in Director) and as a Shockwave piece The getPref and setPref lingo commands reads and writes the text file to the a folder called “Prefs” in the Plug-In Support Folder. As a projector it actually creates a folder (if it does not already exist) and text file within it at the same level.
Profile

1) First of all we will need to create a new Director Movie, and 2 internal casts. The “Internal” cast will contain all the code and the body parts will contain the graphics.
We will create a profile that will be used.
Profile will be:

A) name
B) email
C) password
D) hairtype
E) facetype
F) shirtype
G) pantstype
H) shoestype

This will be converted to a property list, something like this:

gDataList = [#names: "guest", #email: "none", #passoword: "guest", #hair: "hair1", #head: "head1", #shirt: "shirt1", pants: "pants1"]

This will be the base for the cast members “changeBodyParts”, “makeProfile”, “readProfile” and “startOverProfile”.

You can change the properties simply by using dot syntax (or use setaprop).

Setprop gDataList, #name, "John"
gDataList.name = "John"

Or retrieve them.

Thename = gDataList.name

2) We will need to get information from the graphics and text fields, save it to a text file, pull it out again and then convert it back to a list. I can’t believe I put all that in one sentence.

The #names, #email, and #password are text fields and all the other are graphic elements for the avatar parts.

We will use the setPref and getPred lingo commands to do all of this.

Lets look how these commands will look:

Setpref ("ssOnePref.txt", string(gDataList))

This will write a prefs.txt file to the users hard drive. This file will be located into a folder named “Prefs” at the same level as the application itself (when it is saved as a projector). The file can be named what ever you like but we named it ssOnePref.txt.
When you want to read the txt file it will look like this:

Myreadout = Getpref ("ssOnePref.txt")

Off course, since it's a text file you can't get too the values yet. First you need to convert the string back to a list. The value() command usually works well for this.

gDataList = value(Myreadout)

Then you can access the list again using common list commands like explained above. Beware that testing this out in the development environment sometimes results in an error so save it out to a projector before testing.

3) Now that we have got that out of the way lets look on how we will send the text fields and avatar body parts information to the list and then create a text file out of it.
on mousedown me

gDataList = [#names: "guest", #email: "none", #password: "guest", #hair: "hair1", #head: "head1", #shirt: "shirt1", pants: "pants1"]

-- We will need to send information from the 3 text areas and the graphics.

saveName = member("names").text
Setaprop gDataList, #names, saveName

saveEmail = member("email").text
Setaprop gDataList, #email, saveEmail

savePassword = member("password").text
Setaprop gDataList, #password, savePassword


if sprite(19).member = member("hair1") then
Setaprop gDataList, #hair, "hair1"
else if sprite(19).member = member("hair2") then
Setaprop gDataList, #hair, "hair2"
else if sprite(19).member = member("hair3") then
Setaprop gDataList, #hair, "hair3"
end if

if sprite(18).member = member("head1") then
Setaprop gDataList, #head, "head1"
else if sprite(18).member = member("head2") then
Setaprop gDataList, #head, "head2"
else if sprite(18).member = member("head3") then
Setaprop gDataList, #head, "head3"
end if

if sprite(17).member = member("shirt1") then
Setaprop gDataList, #shirt, "shirt1"
else if sprite(17).member = member("shirt2") then
Setaprop gDataList, #shirt, "shirt2"
else if sprite(17).member = member("shirt3") then
Setaprop gDataList, #shirt, "shirt3"
end if

if sprite(16).member = member("pants1") then
Setaprop gDataList, #pants, "pants1"
else if sprite(16).member = member("pants2") then
Setaprop gDataList, #pants, "pants2"
else if sprite(16).member = member("pants3") then
Setaprop gDataList, #pants, "pants3"
end if


Setpref ("ssOnePref.txt", string(gDataList))

end

4) After adding to the list and creating a file out of it you may want to read it. After all it is a profile. After the user goes back to our little application they will want to know that it is there little avatar and profile that is there. It is done something like this.

on enterFrame


Myreadout = Getpref ("ssOnePref.txt")
gDataList = value(Myreadout)
member("names").text = getaProp(gDataList, #names)
member("email").text = getaProp(gDataList, #email)
member("password").text = getaProp(gDataList, #password)


if getaProp(gDataList, #hair) = "hair1" then
sprite(19).member = member("hair1")
else if getaProp(gDataList, #hair) = "hair2" then
sprite(19).member = member("hair2")
else if getaProp(gDataList, #hair) = "hair3" then
sprite(19).member = member("hair3")
end if

if getaProp(gDataList, #head) = "head1" then
sprite(18).member = member("head1")
else if getaProp(gDataList, #head) = "head1" then
sprite(18).member = member("head1")
else if getaProp(gDataList, #head) = "head1" then
sprite(18).member = member("head1")
end if


if getaProp(gDataList, #shirt) = "shirt1" then
sprite(17).member = member("shirt1")
else if getaProp(gDataList, #shirt) = "shirt2" then
sprite(17).member = member("shirt2")
else if getaProp(gDataList, #shirt) = "shirt3" then
sprite(17).member = member("shirt3")
end if


if getaProp(gDataList, #pants) = "pants1" then
sprite(16).member = member("pants1")
else if getaProp(gDataList, #pants) = "pants2" then
sprite(16).member = member("pants2")
else if getaProp(gDataList, #pants) = "panstt3" then
sprite(16).member = member("pants3")

end if
end