tictac
tictac

Reputation: 43

Image to Object with as3

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?

Upvotes: 1

Views: 513

Answers (3)

Juan Pablo Califano
Juan Pablo Califano

Reputation: 12333

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.

Upvotes: 1

falomir
falomir

Reputation: 1169

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;
}

Upvotes: 1

dcolumbus
dcolumbus

Reputation: 9722

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.

Upvotes: 0

Related Questions