AllExperts > Experts 
Search      

Macromedia Director

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Macromedia Director Answers
Question Library

Ask a question about Macromedia Director
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Kevin Fraser
Expertise
I have been programming since 1975. I will answer questions on Macromedia Director and its Lingo programming language. I have worked as a full time Lingo developer on several commercially released educational CD-ROM projects for a total of about three years at a major University software lab. cannot answer q`s about Macromedia Flash. I know Director, not Flash

Experience
Graduate of the Vancouver Film School Multimedia program, member of the SFU Excite Lab at Simon Fraser University, Director and CTO, Tencrows.com Technologies Inc.
 
   

You are here:  Experts > Computing/Technology > Web Design > Macromedia Director > Shopping Basket effect in Director 8

Topic: Macromedia Director



Expert: Kevin Fraser
Date: 5/29/2001
Subject: Shopping Basket effect in Director 8

Question
Hello there! I'm using director 8 on a NT 4 pc.
I'm trying to achieve a 'shopping basket' effect for a CD ROM. Effectively, there is a object on the screen made up of several parts. When certain parts are 'rollover'd' the part number is shown, I would then like to be able to click on this part number to add it to another piece of the movie (possibly a seperate movie), where they can be seen and costings can be equated,  then parts can be deleted from the list if required.
Therefore, could you please inform me of any Lingo that will:
a) place text somewhere different
b) delete text from the 'somewhere'
c) calculate totals.
Hope that's not too cheeky, but as yet I'm not sure of the best way to approach it!
I look forward to your reply. Thanx.

Answer
I'm not going to write you a complete solution, of course. I normally charge for that  :)

However, here's something you can try that should definitely shed some light for you and show you the rich set of possibilities for handling your requirement using somre Lingo-based database handlers you can construct yourself.  If you've never used property lists in Lingo before, it's also an excellent introduction to one of the most powerful, little-used, and little understood features of Director.

Make a new field type cast member and name it 'datatable'

Paste this text into it, or make a simple comma-delimited list using any other software:

partNmbr, partName, partPrice
72-6134a,Widget tightener,123.43
6238,Widget tightener,18.23
sh-276, Widget remover, 24.34
726-GHS, Widget polish-per can, 8.23

Now make a new Movie script and paste this in:

-- sets up database table as a global property list
-- accessable from any handler
on initDB
 global gBasket
 set gBasket = [:]
 set the floatprecision = 2
 set dataTable = field "datatable"
 
 delete dataTable.line[1] -- field header record
 
 repeat while dataTable <> EMPTY
   
   set rawRec = dataTable.line[1]
   delete dataTable.line[1]
   
   set partNmbr = string(rawRec.item[1])
   set partName = string(rawRec.item[2])
   set partPrice = float(rawRec.item[3])
   set inbasket = FALSE
   
   set partData = [:]
   
   partData.addProp(#partName, partName)
   partData.addProp(#partPrice, partPrice)
   partData.addProp(#inBasket, FALSE)
   
   gBasket.addprop(partNmbr, partData)
   
 end repeat
 
 put gBasket
 
end

-- chows current total cost for selected items
on basketTotalCost
 global gBasket
 set invCount = gBasket.count
 set totalCost = 0
 repeat with thisItem = 1 to invCount
   if gBasket.getaprop(gBasket.getpropat(thisItem)).inbasket = TRUE then
     set thisCost = gBasket.getaprop(gBasket.getpropat(thisItem)).partPrice
     set totalCost = totalCost + thisCost
   end if
 end repeat
 return totalCost
end


Now, try this in your message window:

initdb

You should get this back, depending on what you put in the field.

-- ["72-6134a": [#partName: "Widget tightener", #partPrice: 123.43, #inbasket: 0], "6238": [#partName: "Widget tightener", #partPrice: 18.23, #inbasket: 0], "sh-276": [#partName: " Widget remover", #partPrice: 24.34, #inbasket: 0], "726-GHS": [#partName: " Widget polish-per can", #partPrice: 8.23, #inbasket: 0]]

This is a property list. If you've never seen one, study it until you understand it exactly. It's quite logical and simple. It's also what power, flexibility and speed looks like in Lingo.  Also consider how easy it is to edit or update your database by just editing the field.

Try playing with queries to get the data out that you need:

-- to get a record by part number:
put gBasket.getaprop("6238")
-- [#partName: "Widget tightener", #partPrice: 18.23, #inbasket: 0]

-- to get the part name of a part by its number:
put gBasket.getaprop("6238").partName
-- "Widget tightener"

-- to get the part number of row three of your data table
put gBasket.getpropat(3)
-- "sh-276"

-- to put item 3 in the shopping basket:
set gBasket.getaprop(gBasket.getpropat(3)).inbasket = true

-- to check if item 3 is in the basket or not:
put gBasket.getaprop(gBasket.getpropat(3)).inbasket
1
-- 1=TRUE, 0=FALSE

-- to check if item 4 is in the basket or not:
put gBasket.getaprop(gBasket.getpropat(4)).inbasket
0

-- put item 4 in the basket:
gBasket.getaprop(gBasket.getpropat(4)).inbasket = true

-- show the running total:
put basketTotalCost()
-- 32.57

You'll want to look up 'property lists' in the Director Docs & help file.

Good luck.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.