Is it better to load a external stylesheet in a view or a mediator

stephenadams1's Avatar

stephenadams1

07 Sep, 2011 11:41 AM

Hi,

I'm trying to load a external style sheet, by passing in the URL of the style sheet through the FlashVars. Then storing this URL in a parameters model class.

My problem is where to load the style sheet, do I load it in the view (which I am doing currently, but the style is not being applied to the textFields in the view as my load complete function is being called in time before the textFields and view is being added to the stage). Or do I load the style sheet and apply the styles all in the mediator? That way I can start the load process in the onRegister function so it loads before the view is added to the stage.

Stephen

  1. 1 Posted by Stray on 07 Sep, 2011 11:52 AM

    Stray's Avatar

    Hi Stephen,

    onRegister happens after the view is added to the stage, so that won't help you.

    I would tackle this in this way:

    1) Have the view initiate in an invisible state

    2) Give the view an 'apply skin' function

    3) Create a 'skinning' factory that takes in a view and loads it with a style sheet.

    4) Have the skinning factory keep a weakly keyed reference to the views it has already skinned, so that it doesn't do them again if not needed

    5) Inject the skinning factory into the mediator

    6) In 'onRegister' of the mediator, pass the view to the skinning factory

    7) Have the skinning factory handle any delay - so if the skin model isn't ready yet then the skinning factory waits for it to be ready and then skins any queued views

    8) Only have the view be 'shown' once it has been skinned by the factory

    Mediators are really only for wiring, they shouldn't actually 'do work' (because they don't persist and their timing is unreliable)

    Stray

  2. 2 Posted by stephenadams1 on 07 Sep, 2011 02:00 PM

    stephenadams1's Avatar

    Hi,

    That sounds great but I think it might be a bit overkill for what I'm trying to achieve. All I have is three text fields in one view that need their style applied to them via a style sheet.

    Is there a simpler way of doing this?

    Stephen

  3. stephenadams1 closed this discussion on 06 Oct, 2011 08:31 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac