# Strange issue embedding backgroundImage via an external CSS file

**URL:** <https://forum.kirupa.com/t/strange-issue-embedding-backgroundimage-via-an-external-css-file/217171>\
**Category:** flash\
**Created:** [February 23, 2007, 6:38pm UTC](https://forum.kirupa.com/t/strange-issue-embedding-backgroundimage-via-an-external-css-file/217171 "2007-02-23T18:38:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![doihaveto](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@doihaveto](https://forum.kirupa.com/u/doihaveto)\
**Post date:** [February 23, 2007, 6:38pm UTC](https://forum.kirupa.com/t/strange-issue-embedding-backgroundimage-via-an-external-css-file/217171/1 "2007-02-23T18:38:16Z")

</div>

I ran into a very strange issue recently, trying to embed a container’s backgroundImage inside a CSS file.

First, I tried embedding directly in source code, and that worked:

```auto

;; Foo.as
;; This works, but is horribly hacky
public class Foo extends Box {
...[INDENT][Embed(source="foo.png")]
var c :Class;
 setStyle("backgroundImage", c); 
[/INDENT]...
}

```

But that’s not what I wanted - I’d rather embed the image in an external CSS file. So I tried this, and it didn’t work:

```auto

;; Foo.as
;; This doesn't work - but it looks like it should
public class Foo extends Canvas {
...[INDENT]styleName = "barStyle"; 
[/INDENT]...
}

;; Bar.css
.barStyle {[INDENT]backgroundImage = [Embed(source="foo.png")];
[/INDENT]}

```

This didn’t work at all - the background image came out empty. So after much experimentation, I finally arrived at this:

```auto

;; Foo.as
;; Works, hooray! But why?

[Style(name="backgroundSkin", type="Class", inherit="no")]
public class Foo extends Box 
{
...[INDENT]styleName = "barStyle";
...
var c :Class = getStyle("backgroundSkin");
setStyle("backgroundImage", c);
[/INDENT]...
}

;; Bar.css
.barStyle {[INDENT]backgroundSkin = [Embed(source="foo.png")];
[/INDENT]}

```

This last form finally works. But I’m completely mystified why it does, and the simple “backgroundImage = Embed…” didn’t.

Is there something magical that happens in the line “var c :Class = getStyle ()”, like a hidden type conversion? Or maybe it’s the “setStyle (“backgroundImage”, c)” that does something special? Any hints or tips would be appreciated. 🙂

Edit: I’m using ActionScript 3 and Flex 2.01.
