Programmatic skinning?
I would like to do programmatic skinning, i.e. depending on
users preferences a skin will be selected along with images which
are part of the skin. Is it possible with Flex 2?
I found the problem. It's in my CSS file. If there's a
"borderStyle"
property as defined below the application hangs. Take out the
"borderStyle" property and the app runs.
See my test code below (FYI: it does not do much. My first
attempt at
border skinning using code)...
GRIDBORDERS.CSS » HERE'S THE PROBLEM
Application
background-color: #FFFAC7;
GridItem
borderStyle: solid;
borderSkin: ClassReference('GridBorders');
GRIDBORDERS.MXML
<?xml version="1.0"?>
<mx:Application pageTitle="Grid Borders"
xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Style source="GridBorders.css"/>
<mx:Grid height="640" width="940">
<mx:GridRow width="100%" height="66%">
<mx:GridItem width="66%" height="100%" >
</mx:GridItem>
<mx:GridItem width="33%" height="100%" >
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="33%" >
<mx:GridItem colSpan="2" width="100%" height="100%" >
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Application>
GRIDBORDERS.AS
package
import mx.skins.*;
import mx.containers.Grid;
import flash.display.*;
import flash.utils.*;
public class GridBorders extends Border
public function GridBorders()
super();
override protected function updateDisplayList( w:Number,
h:Number
):void
graphics.lineStyle( 15, 0xFFFF00, 0 );
graphics.beginFill( 0xFFFF00, 1.0 );
graphics.drawRect( 0, 0, 10, height );
graphics.endFill();
private var _borderMetrics:EdgeMetrics = new EdgeMetrics(1,
1, 1, 1);
override public function get borderMetrics():EdgeMetrics
return _borderMetrics;
Similar Messages
-
Hello folks,
I am looking for best practices advice when (1) creating
custom components and (2) styling and skinning.
I already know how to skin a component part of the Flex
framework. I can make a class extending ProgrammaticSkin and have
my component skinned using CSS to link the component with the
reference to my custom class.
However what about those cases when you are completely
creating a component from scratch?
Imagine a "Freehand Drawing Canvas" component that allows the
user to draw on it and has some buttons to set color styles, line
styles, etc., or imagine a "Screen Flow Gallery" component that
displays visual objects in a fashion similar to Cover Flow in the
Mac.
In many components I am aware you may reuse other components
part of the Flex framework but I am trying to picture an scenario
where you would need to draw everything yourself because there just
isn't something to base it upon so you will end up drawing it from
scratch.
To learn how instead of building one of those components I
mentioned previously I decided to start with something simple that
would illustrate this like a LiteButton component that will behave
just like the Flex mx.controls.Button but will extend UIComponent
and be completely custom drawn.
The component will have a default look and will also be
style-able and skin-able. I will provide styles for users of the
component to modify and regarding skinning anyone can create a
custom ProgrammaticSkin adding its own drawing logic and link it to
the component via CSS with the ClassReference applied to the skin
selector.
So far so good and it's clear what I want to achieve. I
actually know how to do most of the stuff here but I have one
single problem.
Here is my question, where should I put my custom drawing
logic? If I do it in the updateDisplayList inside the class
extending UIComponent it works, however I thought that it would be
a better practice to do it using programmatic skins, that way I
could provide different skin themes for my component set.
The problem is that I can't make the programmatic work in
this scenario. I tried instantiating the custom programmatic skin
during the updateDisplayList of the LiteButton component and adding
it to my display object via addChild but that didn't do anything. I
also tried creating a "default.css" stylesheet and tried to use
ClassReference as I would normally do to skin an already existing
component (or composite component as well) but that didn't do
anything either.
So how do I apply programmatic skins for completely custom
drawn components of my Flex library project?
I could do it inside the updateDisplayList of the LiteButton
class extending UIComponent but again I would like to provide
different theme sets for my components so it makes sense using
programmatic skins."jbucaran" <[email protected]> wrote in
message
news:[email protected]...
> Hello folks,
>
> I am looking for best practices advice when (1) creating
custom components
> and
> (2) styling and skinning.
>
> I already know how to skin a component part of the Flex
framework. I can
> make
> a class extending ProgrammaticSkin and have my component
skinned using CSS
> to
> link the component with the reference to my custom
class.
>
> However what about those cases when you are completely
creating a
> component
> from scratch?
>
> Imagine a "Freehand Drawing Canvas" component that
allows the user to draw
> on
> it and has some buttons to set color styles, line
styles, etc., or imagine
> a
> "Screen Flow Gallery" component that displays visual
objects in a fashion
> similar to Cover Flow in the Mac.
>
> In many components I am aware you may reuse other
components part of the
> Flex
> framework but I am trying to picture an scenario where
you would need to
> draw
> everything yourself because there just isn't something
to base it upon so
> you
> will end up drawing it from scratch.
This may help with that
http://livedocs.adobe.com/flex/3/html/help.html?content=skinstyle_3.html
> To learn how instead of building one of those components
I mentioned
> previously I decided to start with something simple that
would illustrate
> this
> like a LiteButton component that will behave just like
the Flex
> mx.controls.Button but will extend UIComponent and be
completely custom
> drawn.
>
> The component will have a default look and will also be
style-able and
> skin-able. I will provide styles for users of the
component to modify and
> regarding skinning anyone can create a custom
ProgrammaticSkin adding its
> own
> drawing logic and link it to the component via CSS with
the ClassReference
> applied to the skin selector.
>
> So far so good and it's clear what I want to achieve.
Actually after
> playing
> with the weekend and today I know how to do most of the
stuff but I have
> one
> single problem. So here is my question, where should I
provide my custom
> drawing logic? If I do it in the updateDisplayList
inside the class
> extending
> UIComponent it works, however I thought that it would be
a better practice
> to
> do it using programmatic skins, that way I could provide
different skin
> themes
> for my component set.
These aren't mutually exclusive. When you provide a skin with
a
TypeSelector, you have to add it to the display list
somewhere, and this is
typically done in updateDisplayList or addChildren. I prefer
to do it in
updateDisplayList, because you can then change it if the
style changes.
> The problem is that I can't make the programmatic work
in this scenario. I
> tried instantiating the custom programmatic skin during
the
> updateDisplayList
> of the LiteButton component and adding it to my display
object via
> addChild but
> that didn't do anything.
Exactly what did you do?
> I also tried creating a "default.css" stylesheet and
> tried to use ClassReference as I would normally do to
skin an already
> existing
> component (or composite component as well) but that
didn't do anything
> either.
I've never had any problem using an approach similar to
this...but I will
say that I couldn't see any advantage in creating a
default.css style sheet,
since it's not really default in the way that the one that
comes with Flex
is. It's much more obvious to anyone using your component
what's going on
there if you create a style sheet where they're likely to
spot it.
> So how do I apply programmatic skins with the default
look for custom
> drawn
> components?
It seems like your approach is fine, but maybe you've made a
mistake in your
implementation.
> I could do it inside the updateDisplayList of the
LiteButton class
> extending
> UIComponent but again I would like to provide different
theme sets for my
> components so it makes sense using programmatic skins.
You might want to consider also adding an instance of
HaloBorder to your
component. That brings a lot of functionality with it.
HTH;
Amy -
Flex Builder Design View programmatic skinning
I am writing programmatic skins, by extending
ProgrammaticSkin class. If i apply these skins to mx:Button, i can
see the skin in Flex Builder design view. But when i style my
custom component with programmatic skins, Flex Builder design view
does not show the skin, though the skin is applied when i run the
application. Is there a way for me to write my custom classes
(class Node extends UIComponent), and apply skins, so that i can
see the skins in Flex Builder design view.Actually I found the answer to my question. You can find it
in my blog.
programmatic
skinning in Flex Builder Design view -
Flex Bug - Programmatic Skinning!
I believe I found a Programmatic Skinning bug in Flex.
Whenever I set the "borderSkin" property to a custom skin
class, the flash player hangs in all browsers, the CPU peaks around
95% and memory is consumed rapidly.
After waiting for about 10 minutes I get the following...
[SWF] C:\Documents and Settings\Chris.Simeone\My
Documents\Flex Builder 2\Skinning-Lessons\bin\gridBorders-debug.swf
- 408,071 bytes after decompression
undefined
at
mx.core::UIComponent/getClassStyleDeclarations()[C:\dev\GMC\sdk\frameworks\mx\core\UIComp onent.as:6810]
at
mx.styles::StyleProtoChain$/mx.styles:StyleProtoChain::addProperties()[C:\dev\GMC\sdk\fra meworks\mx\styles\StyleProtoChain.as:142]
at
mx.styles::StyleProtoChain$/mx.styles:StyleProtoChain::addProperties()[C:\dev\GMC\sdk\fra meworks\mx\styles\StyleProtoChain.as:173]
(FYI: The previous error line is repeated 191 times)
I tried tracing my custom skin class (by setting breakpoints)
but none of the code ever fires - the debugger never goes into the
code.
When I remove this line from my CSS file -
borderSkin:ClassReference('GridBorders'); - the application
runs fine.
To test this further I grabbed the example on the bottom of
this
page
and the same exact error occurs. Note it the "borderSkin" property
is set on the VBox tag.
I tested other programmatic skinning examples that use
upSkin, downSkin, etc and they all work fine. I only have this
problem when assigning a skin class to the "borderSkin" property.
Would someone please confirm this is bug? I followed the
Programmatic skins recipe to the letter.
Thanks
Chris SimeoneI found the problem. It's in my CSS file. If there's a
"borderStyle"
property as defined below the application hangs. Take out the
"borderStyle" property and the app runs.
See my test code below (FYI: it does not do much. My first
attempt at
border skinning using code)...
GRIDBORDERS.CSS » HERE'S THE PROBLEM
Application
background-color: #FFFAC7;
GridItem
borderStyle: solid;
borderSkin: ClassReference('GridBorders');
GRIDBORDERS.MXML
<?xml version="1.0"?>
<mx:Application pageTitle="Grid Borders"
xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Style source="GridBorders.css"/>
<mx:Grid height="640" width="940">
<mx:GridRow width="100%" height="66%">
<mx:GridItem width="66%" height="100%" >
</mx:GridItem>
<mx:GridItem width="33%" height="100%" >
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="33%" >
<mx:GridItem colSpan="2" width="100%" height="100%" >
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Application>
GRIDBORDERS.AS
package
import mx.skins.*;
import mx.containers.Grid;
import flash.display.*;
import flash.utils.*;
public class GridBorders extends Border
public function GridBorders()
super();
override protected function updateDisplayList( w:Number,
h:Number
):void
graphics.lineStyle( 15, 0xFFFF00, 0 );
graphics.beginFill( 0xFFFF00, 1.0 );
graphics.drawRect( 0, 0, 10, height );
graphics.endFill();
private var _borderMetrics:EdgeMetrics = new EdgeMetrics(1,
1, 1, 1);
override public function get borderMetrics():EdgeMetrics
return _borderMetrics; -
Change item programmatic skin at runtime
AS3 lets you programatically skin a class. For example, on
MenuBar control. you can tell an instance of a menuBar which skin
to use when a mouse clicks on it, with the following line:
myMenuBar.SetStyle("itemDownSkin",
myProgrammaticSkinClassName);
However, let's say you want to change to another class after
the menubar has already been created? At this point the SetStyle
function has no effect as the menubar has continues to display a
cached appearance of itself. It seems your only option is to
destroy the existing control and recreate it with the new style.
Is there a more straightforward way to dynamically change the
skin of a control after it has been created?
Thanks to anyone out there! edHello,
You cannot change the width of a field at runtime.
You can use the elasticity property. The field size will be
increased according to its content.
Regards -
I have created button inside a class. I want to skin it using
image. I have written following line
btn.setStyle("upSkin","img.jpg");
But it gives error. Can some body please help me .This little snippet might do the trick if you are selecting from a known list that is pre-determinable.
Esentially I cheated by floating the boolean over a picture ring and setting the BG color of the boolean to transparent. You still can't paste a new picture into a picture ring at run-time so this may not be exactly what you are looking for.
Jeff -
Programmatic skinning, charts and images. Oh My!
So here is a sample of the code I'm working with:
for (var i:int = 0; i< numBlocks; i++) {
var tmpImg:Image = new Image();
tmpImg.source = "test_disc_one.png";
tmpImg.y = startY - (8*i);
tmpImg.blendMode = BlendMode.NORMAL;
trace("["+i+"]: " + this.parent);
parent.addChild(tmpImg);
This code is triggered when updateDisplayList() is called on
the ColumnSeries within my chart. (<mx:ColumnSeries
id="actualColumn" yField="Score" name="actual"
itemRenderer="com.test.IconicBlockRenderer" />) I'm trying to
display the png for each datapoint on the graph. There is some
tweaking and programmagic stuff behind it (determine different
images and such based on values) . I have tried using
graphics.beginBitmapFill() with bitmaps but whereever the images
intersect becomes transparent. And calling parent.addChild above
locks the player into and endless loop. I'm at a loss on this one.
Any help thoughts, pointing of directions would be helpful.
I should also mention that the code itself works. When
dropped into <mx:Application><mxScript> it works like a
charm. When I tried moving it into the chart renderer all I got was
empty space the images don't show up.
Additionally, is it even possible to pass parameters to the
renderer? Meaning is it possible to do something *like*
<mx:ColumnSeries id="actualColumn" yField="Score"
name="actual" itemRenderer="com.test.IconicBlockRenderer(tArray)"
/>
_AnthonyGuys,
I know it wasn't that simple so I did not get any reply for this thread. Thanks for all your support.
we have found a solution for this issue.
Steps we did was
1. Right-click My Computer and click Manage.
2. Navigate to Services and Applications > Internet Information Services (IIS) Manager > Web Sites > Default Web Site.
3. Right-click crystalreportviewers115 and then click Properties.
4. On the ASP.NET tab, choose a 2.0.x version from the ASP.NET Version list.
5. Click the Apply button and then click OK.
6. Right-click businessobjects and click Properties.
7. On the Virtual Directory tab, click the Configuration button.
8. Check the path of the mappings and note the version number (in the path ...\Framework\vX.X...)
9. Repeat steps 2 to 5 for crystalreportsviewers115.
If the paths for businessobjects and crystalreportviewers115 are different, change one or the other so that they point to the same version of .NET Framework.
10. Stop and restart the Default Web Site.
Thanks
-Azhar -
Hi,
From what I read, Flex hero mobile theme has been built using FXG skins written in AS.
Actually, I'm looking at a quick sample of how to build custom lightweight mobile skins.
I've looked at the mobile theme given with hero SDK but it's only a SWC file so I can't see the source code.
This is how I would build a mobile skin :
1) Create an AS class that extends SparkSkin/Skin (depends if I plan to use styles)
2) Define SkinState with AS3 metadata
3) Create and add the required skinparts to the display list (createChildren method?)
4) Add FXG elements in AS (something like that : http://saturnboy.com/2010/11/programmatic-skinning-in-flex-4-an-fxg-clock/). Where should I do that, updateDisplayList method?
Please tell me if I'm wrong or anything
ThanksAny tips?
-
Flex skins - compile time or not?
Hi there, I am sorry if this seems like too simple of a
question, but I have searched around and I don't even know if I am
looking for the right words to ask this with. Put as simply as
possible, if I am developing a skin for an application that we will
then give to our customers, will they have to recompile the app in
order to change the skin or will they have the ability to put a new
skin into the app after it has been compiled and released? Is the
skin embedded in the app or is it held separately? Is there a
difference between using graphical vs. programmatic skins at
compile time? Thanks for any help you can give me, and Happy New
Year!The application can use a compiled CSS file and load it at
runtime, but the app must be set up to use it before it is
compiled. Then you can swap out the swf with a new one and it will
work as long as all the style names and style assignments are the
same as the old one. You cannot add a swf with skins to an existing
app without setting it up first and compiling the app. -
hi,
there are a lot of blog posts and excellent documentation on using runtime css.
however, none of them really address the *why*.
the adobe docs say:
"By loading style sheets at run time, you can load images (for graphical skins), fonts, type and class selectors, and programmatic skins into your Flex application without embedding them at compile time. This lets skins and fonts be partitioned into separate SWF files, away from the main application. As a result, the application's SWF file size is smaller, which reduces the initial download time. However, the first time a run-time style sheet is used, it takes longer for the styles and skins to be applied than if you load styles by using the <mx:Style>
tag. This is because Flex must download the necessary CSS-based SWF file while the application is starting up or running."
from what i gather:
- it's good because i've separated my styling code from my application code. ok, fine. not critical tho.
- reduces initial download time? fine. but I still can't display my app because I have to wait for the css swf to be download first and then be applied (which takes longer to apply at runtime)
- takes more code to apply the style, when to apply it in the initialization phase, and how to avoid flicker of original halo style
- i've seen a few posts on problems with css and modules
do i need to swap css styles at runtime? no.
but lets assume i want to change the style in the future to give it a fresh look. i could simply replace the css swf on the server and only that swf will be downloaded and updated in the users browser cache. correct? great. for all that architectural pain, i've saved them a few extra kilobytes of download time.
and what about themes? the halo theme is the default and compiled into your app *regardless* of whether u use runtime css or compile time css. so u may as well build a theme swc to begin with.Some folks have apps that swap themes/skins at runtime sort of like Windows Media Player.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui -
CSS file compiled into SWF...
Hello,
I have a problem with all my css files in my Flex project. I
need them to be compiled into SWF because its the only way to load
and switch them at runtime.
I use a ClassReference to a custom programmatic skin in the
css file:
skin: ClassReference(
"com.someawsomepackage.util.manager.SkinManager" );
MY PROBLEM is that I HAVE TO place the various css file in
the ROOT folder of my project so that the compiler can find and
compile this classreference along with the css.
I would like to place the css files into a style folder...
But I will get a compile error if I do so.
Anyone has an idea ? thx !did you try compiling them manually from the command line using mxmlc?
-
I have built an interface in Flash CS3 and now have the need
to port it over to Flex. I am trying to do it with as little
re-build as possible, so I need to port the Flash components over
with it. I exported a SWC with all of the components I am using,
and added it to the Library Path of an AS project.
The build gives me no errors, but I do get a #2007 at
runtime. The error seems to be stemming from a Yahoo ASTRA Flash
component, which was included in the SWC.
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()
at fl.controls::LabelButton/draw()
at fl.controls::Button/draw()
at
com.yahoo.astra.fl.controls.tabBarClasses::TabButton/draw()
at fl.core::UIComponent/drawNow()
at com.yahoo.astra.fl.controls::TabBar/drawButtons()
at com.yahoo.astra.fl.controls::TabBar/draw()
at fl.core::UIComponent/callLaterDispatcher()
I have been searching around the net, and the majority of
people are saying that this happens when the skins aren't included
(so you need to set them before the component is added to the
stage). I am using customized programmatic skins, for which the
source files are included in the build, and the styles get set
before the component is added to the stage (I actually replaced the
default ones in the class).
Does anyone have any other ideas as to how I could fix this?
PS - It is an ASTRA TabBar component that is giving me
issues. I know that Flex has a TabBar and TabNavigator, but I can't
find any documentation on how to use these from an AS project (no
MXML). I will simply rebuild using the native Flex controls if
necessary, and if possible, but would prefer to fix the issue as it
currently stands. (I might go back to Flash at some point, and
don't want to tie myself to a particular solution, considering I
can't use Flex components in Flash).
PPS - If you are wondering why I am porting to Flex right
now, especially if I am considering taking it back to Flash in the
future, it is because I have the need to begin building in
FlashPlayer 10 functionality, and the only way you can build to
FP10 right now (as its in beta) is with a nightly build of
Flex."rritchey" <[email protected]> wrote in
message
news:g8ua6d$qu6$[email protected]..
> bump: Was I not clear in my question? Or does no-one
know the answer?
You might want to try in the flexCoders Yahoo! group. -
LinkBar: how to set a selected button's background color?
I was able to set the text color of a selected LinkBar button by "disabledColor" style of LinkBar. Accordingly, I expect to set the background color of the selected button by "backgroundDisabledColor" style, however, it didn't work; and except "backgroundDisabledColor", I didn't see any other style that could possibly achieve this. Please help. Thanks.
Solved this myself by writing a programmatic skin and set it to LinkButton's disabledSkin.
-
Passing values to a ProgrammaticSkin
I it possible to pass values to a programmatic skin?
I want to customise the apperance of a button based upon a value, for example in the code below (used to create a custom button) I would like the id value to influence how the skin is drawn.
public function CustomButton(idIn:String)
super();
width=64;
height=128;
id=idIn;
setStyle("upSkin",CustomButtonSkin);
setStyle("overSkin", CustomButtonSkin);
setStyle("downSkin",CustomButtonSkin);
thanks benBen,
I'd recommend you use styles to pass information to your skin. Any styles set on your CustomButton will be passed down to the CustomButtonSkin.
Also, I'd recommend using a style Type selector instead of using setStyle to set the button skins.
<mx:Style>
CustomButton
skin : ClassReference("CustomButtonSkin");
</mx:Style>
Jason -
Setting an undeclared style in MXML
Hi folks,
for a component that renders via a programmatic skin I would like to set style values in MXML, which are not declared by the component.
Lets say I had developed a skin for a button that makes the border blink, and I need a "border-blink-color" style.
The following code obviously wouldn't work
<mx:Button borderBlinkColor="#ff8822" label="Test" />
however, setting it via CSS or AS works.
Now is there a way to achieve my goal using MXML?Did you try giving your button an id and setting the style in actionscript?
In a creationComplete handler:
myButton.setStyle("borderBlinkColor", 0xff8822);
<mx:Button id="myButton" borderBlinkColor="#ff8822" label="Test" />
-Darrell
Maybe you are looking for
-
Hi Frnds, i have 3 interfaces separately in my environment. 3 interfaces have 3 sender file channels.All 3 channels need to pick the file from same dropzone(abc/xyz/).But file names will differs. Lets asssume 1st channel will pick the file name start
-
Grouping by the results of a group by
I want to group the results of a query that itself is a group by (I have simplified it). select Id, MAX(type), MIN(type), COUNT(*) from aa group by Id gives 1 03 01 2 2 03 01 2 3 01 01 1 4 03 01 2 5 03 01 3 and so on (there are over 100,000 rows in m
-
Urgent Help reg setting the maxlength of a text box
Hi all, I want to set the max length or the no of characters to be entered of a textbox in parent page from a child popup window. Even if i use the opener property the maxlength is not set. Is there any other way to set the property. I'm not refreshi
-
Hi, Please can you tell, How to work with Business Graphics UI Element with Brief steps Regards, Boots.
-
Workflow Test Data for BUS1010
Hello experts, i have a problem when testing my new workflow. I use BUS1010 for setting up credit data for debitors. I set test data for all BO like BUS2032. There is the key field 12 character long so I enter 0000012092 for my salesorder and for KNA