Why this image is not draggable?

Hi folks!!
Here again with this “simple” question.
In my code I run a sprite, then another sprite, and at the end I show an image that I need to be draggable.
But the problem is that this last image isn’t draggable, the listener event is not working.

here is the code.

[lua]local ui = require( “ui” )
local baseline = 250
local sprite = require(“sprite”)
local instance1 = nil
local instance2 = nil

local function displayimage(event)
if (event.phase == “end”) then
–***THIS IS THE IMAGE I NEED TO BE DRAGGBALE
cop4 = display.newImage( “pisco.jpg”, true )
cop4.x = 96
cop4.y = 170
end
return true
end

local function nextSprite(event)
if (event.phase == “end”) then
–****SECOND SPRITE***********
instance1:removeEventListener( “sprite”, nextSprite)
local sheet2 = sprite.newSpriteSheet( “fase2.jpg”, 125, 200 )
local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 8)
sprite.add( spriteSet2, “b”, 3, 6, 2300, 1)
instance2 = sprite.newSprite( spriteSet2 )
instance2.x = display.contentWidth / 4 + 16
instance2.y = baseline - 75
instance2:prepare(“b”)
instance2:play()
instance2:addEventListener( “sprite”, displayimage)
end
return true
end

–**************BOTON*************************
local button1Press = function( event )
–****FIRST SPRITE***********
local sheet1 = sprite.newSpriteSheet( “fase1.jpg”, 125, 200 )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8)
sprite.add( spriteSet1, “a”, 1, 8, 170, 3)
instance1 = sprite.newSprite( spriteSet1 )
instance1.x = display.contentWidth / 4 + 16
instance1.y = baseline - 75
instance1:prepare(“a”)
instance1:play()
instance1:addEventListener( “sprite”, nextSprite)
end
local button1 = ui.newButton{
default = “buttonRed.png”,
over = “buttonRedOver.png”,
onPress = button1Press,
onRelease = button1Release,
text = “Buscar Tip”,
emboss = true
}
button1.x = 160 ; button1.y = 350
–*********************************************

–*******************DRAG IMAGE******************
local function startDrag( event )
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
–t.x0 = event.x - t.x
t.y0 = event.y - t.y
– Make body type temporarily “kinematic” (to avoid gravitional forces)
event.target.bodyType = “kinematic”
– Stop current motion, if any
event.target:setLinearVelocity( 0, 0 )
event.target.angularVelocity = 0
elseif t.isFocus then
if “moved” == phase then
–t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
if ( not event.target.isPlatform ) then
event.target.bodyType = “dynamic”
end
end
end
return true
end
–***Assigning the last image to the draggable function
cop4:addEventListener( “touch”, startDrag )
–************************************************[/lua]

Thanks in advance. [import]uid: 54055 topic_id: 14447 reply_id: 314447[/import]

You have a coding error. It should be ended, not end.

[lua]if (event.phase == “ended”) then [/lua]

Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 14447 reply_id: 53486[/import]

@Jordan,
I think that end for the sprite events is correct. Source : here

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14447 reply_id: 53503[/import]