Hello
is there some way to select object by id or name
like in JavaScript
Thank you!
[import]uid: 147488 topic_id: 26660 reply_id: 326660[/import]
Hello
is there some way to select object by id or name
like in JavaScript
Thank you!
[import]uid: 147488 topic_id: 26660 reply_id: 326660[/import]
Normally you store your objects in variables using some variable name:
ball = display.newImageRect(“ball.png”, 64, 64)
and you would know that ball is, well. ball.
Now you could put all of your objects into a big table:
local objectTable = {}
objectTable[“ball”] = ball
or you could use dot notation:
objectTable.ball = ball
but since you are apparently wanting some kind of DOM like structre, the first method is closer.
Then you could later do:
thisBall = objectTable[“ball”]
but why do that when you can just use
thisball = ball
???
All that said, you can also do this:
ball = display.newImageRect(“ball.png”, 64, 64)
ball.name =“ball_1”
Then if you use a display group to contain your objects:
myGroup = display.newGroup()
myGroup:insert(ball)
then myGroup is nothing more than a big table of the display objects in it and you could traverse through the group looking for something by the name you gave it.
[import]uid: 19626 topic_id: 26660 reply_id: 108147[/import]
Hello thank you for your answer!
The reason i want to use getElementById is for example
dynamic created objects or similar
I see now that i easy can do a lookup table my self thanks to your example
Thank you [import]uid: 147488 topic_id: 26660 reply_id: 108441[/import]