質問

I'm trying to use images in arrays - I come from a Java background so I'm thinking that the image is an Object, and when I put it in the array, I'd expect all the properties of the object to be maintained. This doesn't appear to be the case.

Here's my code :

put image sheep into animalarray[1]
answer the short name of image sheep
put animalarray[1] into  temp
answer the short name of temp 

I'd expect the the first two lines of code to be equivalent to the second two lines of code - but they aren't. The first two lines do what I'd expect ( they display the short name of my "sheep" image). The second two lines produce a runtime error as the fourth line executes. ( Chunk error in object expression )

Once I put an image into an array, does it cease to be considered to be an image object? Should I stop thinking about objects?

The more I use LiveCode, the less I understand it ...

役に立ちましたか?

解決

You'll want to do something like this:

put the imagedata of image sheep into animalarray[1]

or this

put the text of image sheep into animalarray[1]

the imagedata is basically a bitmap (sequential sets of 4 bytes, ARGB) representing the image on screen as it appears. this property changes at the image changes, i.e. if you set the width for example, the imagedata property changes to reflect this

the text is the binary data (i.e. file) that is the 'source' of the image. this remains the same after manipulating the image object in the ide.

他のヒント

I think @David Williams has answered this well but here goes for some more info:

In LiveCode objects and variables are not the same thing. Objects have a default property named 'text' so if you put image X into theImage you are putting the text of the object into the variable. The text here is PNG, JPEG etc data.

If you really want the properties of an object to be put into a variable you can do that with the properties property:

put the properties of image sheep into animalarray[1]
answer animalarray[1]["name"]

If what you really want is something like a pointer to the original object then as David points out in his comment use:

put the long id of image sheep into animalarray[1]
answer the short name of animalarray[1]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top