Hello!
I'm trying some code using the director class.
I've work with 2 scenes (scene1, scene2).
Please, pay attention to this: At scene1 I press a button, go to scene2, press another button at scene2 and come back to scene1, press the same button go again to scene2 and finally press another button that show me an image.
With this code everything is ok:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | module(..., package.seeall) local ui = require("ui") local scrollNav = require("scrollNav") local contido = require("contidoSlider") local localGroup = display.newGroup() local sliderPrincipal local sliderSecundario local slider2 local ancho,alto=display.contentWidth,display.contentHeight local fondo=display.newImage("fondo.jpg") local accionInicio = function (event) if event.phase == "release" then director:changeScene("escena1","moveFromLeft") end end local function elementoElexido(event) slider2=display.newGroup() local sliderSecundario=display.newImage("fondo_thumb.png",0,0) slider2:insert(sliderSecundario) slider2.x=0 slider2.y=alto-150 localGroup:insert(slider2) end --Buttons local boton_inicio = ui.newButton{ default = "bot_inicio.png", over = "bot_inicio.png", onEvent = accionInicio, emboss = true } local boton_editar = ui.newButton{ default = "bot_editar_es.png", over = "bot_editar_es.png", onEvent = elementoElexido, emboss = true } local function initVars () ----------------------------------- -- Insercións ----------------------------------- localGroup:insert(fondo) localGroup:insert(boton_inicio) localGroup:insert(boton_editar) ----------------------------------- -- Posicionamentos ----------------------------------- boton_inicio.x=40 boton_inicio.y=45 boton_editar.x=40 boton_editar.y=alto-45 end function clean ( event ) --print("escena 2 limpa") end --------------------------------------------------------------- -- Todas as escenas deben ter esta función NEW --------------------------------------------------------------- function new() ----------------------------------- -- Inicializo variables ----------------------------------- initVars() return localGroup end Runtime:addEventListener("scrollNav.elemElexido", elementoElexido) |
If the variable localGroup is global instead of local, no runtime error...
Could anybody tell me the reason?
Sorry if I don't explain good!