FlashComGuru Home InfluxisCDNImediaseeUvault
                                                                                       Forum Index | Active Topics | Register
                                                                                                          List Overview | List Archives
                                                                                                                           About this site | Advertise
 

home

Adobe AIR (11)
Applications (40)
Books & Training (11)
Collaboration (18)
Components (10)
Events (80)
Flash Player (35)
Flex (39)
FMS (110)
General (123)
Hosting (6)
Jobs (17)
Off topic (36)
OSMF (3)
Press Releases (23)
Site Check (11)
Tools (53)
Videos & Players (74)

Follow me on Twitter

 
This is what happens when you stand on the shoulders of giants - you don't quite know what you are doing, at least in my case.
I've been working on a way to dynamically load images into a Flex app and set them as the tiled background of a Canvas component. Luckily I spotted creacog's work which I adapted a little bit for my needs. You can see the results here.

So far the image loading and displaying as a borderskin of the Canvas works, but as you can see when you drag the box around is that as soon as scrollbars appear the image is no longer rendered and the Canvas's background color it displayed instead.

I'd appreciate any tips on this. You can see the sources by right-clicking the app or directly from here (the .zip is here).

Feel free to use and reuse this code if you find it useful, and remember to credit creacog.co.uk who has done the hard work on this.

Comments
[Add Comment]
OK I had a similar problem when moving images but using animations not drag and drop.

The way I resolved it was to have hidden canvases around the main canvas which the image could be moved into and switching of Auto Scroll bars.

Thus having a fixed area on the screen which the image can move round and into.

Enabling the background to stay static.

Well a brief explanation but hopefully enough for a solution.
# Posted By Trevor Ward | 12/22/09 3:47 PM
HI,

Found this method

http://alekkus.com/blog/2009/02/flex-tutorial-sett...

implemented it into your mxml, works fine:

http://buffer.uk.com/preview/flex/bin-release/Imag...

hth,

Neil
# Posted By Neil Edwards | 12/22/09 4:19 PM
that's excellent, thanks. I'll dig into it shortly to see where I have gone wrong.
# Posted By Stefan Richter | 12/22/09 8:06 PM
ah ok so they are using a similar way of setting the image but not implementing it via the borderSkin style. I wonder why it goes wrong with the borderSkin...
# Posted By Stefan Richter | 12/22/09 8:09 PM
The clue is in the style name 'borderSkin', this skin is primarily for borders, not backgrounds.

Some info on whats going on:
When a Container has ScrollBars added to it, it creates a new Sprite inside itself named contentPane, to hold the children, removes the children from itself, and adds the to the contentPane. It then scrolls the view by using a scrollRect on the contentPane.

The contentPane has some of the styles set on the Canvas applied to it (namely background stuff (backgroundDisabledColor, backgroundColor, backgroundAlpha, backgroundImage, background)), and this sits on top of the border which remains at index 0 within the Canvas's rawChildren.


Easiest hack:
Set the backgroundAlpha style to 0. The exact same thing will be happening, but because the background alpha is 0, u won't see it and therefore you will see your 'border' below it.
# Posted By Tink | 12/23/09 12:01 PM
thanks, I got it working now using a modified version of the alekkyus.com approach. I'll post my version as soon as I get a chance. I'm not using the borderSkin class anymore.

Thanks for the explanation, with knowing about the contentPane it makes more sense.
# Posted By Stefan Richter | 12/23/09 1:00 PM
A Canvas handles this by checking whether the style 'backgroundImage' has been set, and it it has, it doesn't give the contentPane an opaque background (so it doesn't cover the image).

So another alternative would be to use the built in style 'backgroundImage' to assign the image, and use that in your skin, instead of adding another style to do the same thing (i.e. your 'bgImage').
# Posted By Tink | 12/23/09 3:01 PM
Another option would be to use a tile list behind your content. I expect it may be overkill for just displaying a tiled background image though.

I guess it depends on your specific implementation.
# Posted By Rob McMichael | 1/5/10 9:49 AM