Friction joint on spawned objects

I am randomly spawning dynamic boxes that are falling on a static deck that moves about the x. My problem is that when I move the deck the boxes that have landed on it don’t move with it. I think I might need a friction joint, but I’m not sure how to create a joint on spawned objects.

I was thinking that assigning a type to the box and deck and creating the joint that way, but I can’t wrap my head around the syntax. Any help would be appreciated. Code is attached below; I used rects so just load and go.

[lua]local physics = require (“physics”)
local mRand = math.random

_W = display.contentWidth
_H = display.contentHeight

function game()
setUpPhysics()
createWalls()
createDeck()
createBoxes()
end

function setUpPhysics()
physics.start()
–physics.setDrawMode(“hybrid”)
physics.setGravity(0,3)
end

function createWalls()

local wallThickness = 10

–left wall
local wall = display.newRect( 0, 0, wallThickness, _H)
physics.addBody(wall, “static”, {friction=0, bounce=0})

–right wall
local wall = display.newRect(_W - wallThickness, 0, wallThickness, _H)
physics.addBody(wall, “static”, {friction=0, bounce=0})

–bottom wall
local wall = display.newRect(_H + 50, _H - wallThickness, _W, wallThickness)
physics.addBody(wall, “static”, {friction=0, bounce=0})
wall.type = “bottomWall”
end

function createDeck()

local deckHeight = 10
local deckWidth = _W/2
local motionx = 0
local motiony = 0

local deck = display.newRoundedRect(_W/2 - deckWidth/2, _H * .75, deckWidth, 10, 2)
physics.addBody(deck, “kinematic”, {friction=.75, bounce=0.01, density=3})
–using touch for testing
local function moveDeck(event)
deck.x = event.x
end

Runtime:addEventListener(“touch”, moveDeck)

–using accel for gameplay
–[[
local function onAccelerate(event)
motionx = 35 * event.xGravity
end

local function movedeck (event)
deck.x = deck.x + motionx
if deck.x <0 then deck.x = 0
elseif deck.x > _W - deckWidth then deck.x = _W - deckWidth
end
end

Runtime:addEventListener (“accelerometer”, onAccelerate)
Runtime:addEventListener(“enterFrame”, movedeck)
]]–
end

function createBoxes()
local function randBox()
local randW = mRand(60, 80)
local randH = randW
local genY = (-50)
local genX = mRand(100, 300)
local randAngle = mRand(0, 5)

local newBox = display.newRoundedRect (genX, genY, randW, randH, 10)
physics.addBody(newBox, “dynamic”, {friction=0.3, bounce=0.01, density=3})
newBox.rotation = randAngle
end
timer.performWithDelay(5000, randBox, 0)
end
game()[/lua] [import]uid: 55934 topic_id: 13341 reply_id: 313341[/import]