views:

52

answers:

3

I'm trying to convert an image in my assets folder

"./assets/image1.png"

to type Object. It needs to be Object because that's what the function I'm using it in is expecting.

Any ideas what would be the simplest way to do this?

A: 

Why don't you create a new Object containing the information about the image... including the path.

var obj:Object = new Object();

obj.path = "/assets/image.jpg";
obj.height = 32;
obj.width = 32;

trace(obj.path);
// or, if Flex
Alert.show(obj.path);

And then just pass the new Object into the function and access it like I have above.

dcolumbus
+1  A: 

Do you mean something like :

[Embed(source="assets/logo.jpg")]
private var logo:Class;

private function init(e:Event):void
{
     this.displayImage(logo as Object);
}

private function displayImage(img:Object):void
{
     //Assuming you have an image control on stage with an instance
     //name of "myImage"
     myImage.source = img;
}
falomir
+1  A: 

If the function you are passing the image to is expecting an Object object, you can in pass anything, it won't reject it. That doesn't mean the function will work correctly, though. Any value will be an Object (except for undefined, which will be accepted but coerced to null and maybe some other strange cases).

So, assuming you didn't write the function yourself, do you have any doc that describes what it expects? Or maybe you have the source code for it?. Otherwise, if the only thing you know about what this function expects is that the parameter must be of type Object... you're in trouble, I think.

Juan Pablo Califano
Hear, hear. @tictac, don't skimp on your background info.
aaaidan