Advertisement
Guest User

Array access problems

a guest
Dec 21st, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bg = new BackgroundLayer
  2.     backgroundColor: "#6441A5"
  3.  
  4. #prepare array to hold each box object
  5. boxArray = []
  6.    
  7. #create 3 box layers via a loop    
  8. for num in [0..2]
  9.         boxArray[num] = new Layer
  10.             width: 100
  11.             height: 100
  12.             midX: 150 + (num * 150 )
  13.             midY: (bg.height / 2 )
  14.             backgroundColor: "#DD2476"
  15.             borderRadius: 20
  16.        
  17.         #boxArray[num].draggable.enabled = true
  18.            
  19.         boxArray[num].states.add({
  20.             clicked: {
  21.                 scale: 0.6,
  22.                 #backgroundColor: "#FF512F"
  23.             }})
  24.            
  25.         boxArray[num].states.animationOptions = {
  26.             curve: "spring(300, 40, 10)",
  27.             time: 0.5
  28.         }
  29.    
  30.  
  31. for num in [0..2]
  32.     boxArray[num].on Events.TouchStart, ->
  33.         this.states.next()
  34.  
  35. #testing that the value is correct
  36. for i in [0..2]
  37.     print "boxArray.midX test: Box " + num + ": " + boxArray[i].midX
  38.  
  39. #getting errors that boxArray[i].midX is undefined
  40. bg.on Events.TouchMove, (event) ->
  41.     #set I to loop as 0, 1, 2
  42.         for i in [0..3]
  43.         # getting the error here that the item is undefined
  44.             delta =
  45.                 x: boxArray[i].midX - Events.touchEvent(event).clientX
  46.                 y: boxArray[i].midY - Events.touchEvent(event).clientY
  47.    
  48.             dist = Math.abs(delta.x) + Math.abs(delta.y)
  49.             alpha = Utils.modulate dist, [0, 150], [0.1, 0.5], true
  50.            
  51.  
  52.             boxArray[i].shadowX = Utils.modulate delta.x, [0, Screen.width /2], [0, 50]
  53.             boxArray[i].shadowY = Utils.modulate delta.y, [0, Screen.height/2], [0, 50]
  54.            
  55.             boxArray[i].shadowBlur = Utils.modulate dist, [0, 100], [0, 35]
  56.            
  57.             boxArray[i].shadowColor = "rgba(0,0,0,#{alpha})"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement