How to user unloadStyleDeclarations? - apache-flex

I have a flex4 applciation (mx+spark). When I use:
FlexGlobals.topLevelApplication.styleManager.loadStyleDeclarations(skinName, true);
This works fine: new style is applied.
The trouble is when I apply a new style, it mixes both: this happens because I need to Unload style first.
I try to unload it with:
FlexGlobals.topLevelApplication.styleManager.unloadStyleDeclarations("style/normal.swf",false);
And I always got an error:
ReferenceError: Error #1069: La property 0 cannot be found on Number
and there is no default value.
at normal/unloadOverrides()[null/normal-generated.as:721]
at normal/unload()[null/normal-generated.as:676]
Any idea on how to load/unload swf css in Flex4?

The styles will be updated the next time one of the following methods is called with the update property set to true:
clearStyleDeclaration()
loadStyleDeclarations()
setStyleDeclaration()
unloadStyleDeclarations()
Typically, if you call the one of these methods multiple times, you set this property to true only on the last call, so that Flex does not call the styleChanged() method multiple times.
More information here.

Related

Assigning anchors dynamically in QML

I am creating 2 elements dynamically in QML and need to assign them each an anchor binding. When I add the anchors.right and anchors.left syntax to the properties object of the createObject() function, the anchors are not working:
current_column_on_left = column_component.createObject(parent_element, {anchors.right: previous_column_on_left.left})
current_column_on_right = column_component.createObject(parent_element, {anchors.left: previous_column_on_left.right})
Qt Creator gives me the annotation/error "Expected token ','". I also tried making them strings and camel case, neither of which worked. However, when I add the property bindings separately using Qt.binding() function, everything works fine:
current_column_on_left.anchors.right = Qt.binding(function(){return previous_column_on_left.left})
current_column_on_right.anchors.left = Qt.binding(function(){return previous_column_on_right.right})
Why is the first code block not working? I would prefer not to have the two extra lines of code if I can avoid it.
The error is because javascript doesn't know what property groups are - only qml does.
This is also invalid logic. In createObject(parent_element, {anchors.left: previous_column_on_left.right}) property previous_column_on_left.right is resolved when qreating the javascript {}-style object, which leaves you bound to a fixed anchor which is never changed. But Qt.binding has a function, and resolves nothing when creating the object, which provides you with the correct binding.

Mixing motion-layout and Teacup

I'm trying to mix motion-layout and Teacup in a RubyMotion project. I've created an example view helper to illustrate my problem:
module Teacup::Layout
def example(name, options = {})
subview UIView, name do
subview UILabel, "#{name}_label".to_sym, text: options[:label]
auto do
horizontal "|-[#{name}_label]-|"
end
end
end
end
When I call example(:example), text: "Test" inside a layout block, my code throws the following exception:
(main)> 2013-10-25 13:40:45.989 rui[55552:80b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
example_label is not a key in the views dictionary.
H:|-[example_label]-|
If I omit the motion-layout code and inspect the views, the example_label view is a child of the example view. What's going on here?
In the documentation for Teacup, it says:
# if you need to apply these to a different view, or if you want to assign
# different names to use in the ASCII strings
# auto(layout_view=self.view, layout_subviews={}, &layout_block)
Due to the 'dynamic' nature of the creation of all these views, and the layout (motion-layout) being in a subview instead of a layout (teacup), it just might be getting confused, though subview and layout are similar.
Anyway, try being very specific about which views are going into the auto block using the suggestion from the documentation, then there can be no ambiguity about what should be in the layout.

Visibility of elements by ID

how come that when I attach onchange by attribute and call it
onchange="validateDate(FPR_CURR_FROM);"
it works, but when I use a ASP .NET validator, and my attached function is called like :
function anonymous() {
ValidatorOnChange(event);
validateDate(FPR_CURR_FROM);
}
I get error: FPR_CURR_FROM is undefined.
First off: I know that using FPR_CURR_FROM to access element is BAD, and I should use getElementByID etc... And I will change it eventually. But as I bumped into that code, I'm curious what caused it - propably visibility of variables I guess.
I think it's a scoping issue, yes, it would take seeing more code and how anonymous is called, but that is what it looks like to me from what I see... One way around that is to attach the FPR_CURR_FROM variable to the window object, and access it via window.FPR_CURR_FROM...

Flex - Why is my custom event not being registered with the following event listener?

printableInvoice.addEventListener(batchGenerated, printableInvoice_batchGeneratedHandler);
Results in this error:
1120: Access of undefined property batchGenerated. I have tried it as FlexEvent.batchGenerated and FlashEvent.batchGenerated.
The MetaData and function that dispatches the even in the component printableInvoice is all right. It I instantiate printableInvoice as an mxml component instead of via action-script it well let put a tag into the mxml line: batchGenerated="someFunction()"
Thanks.
batchGenerated should be a string.
It looks like your application dispatches an event whenever the batch is generated.
I'm assuming inside your code you have something along the lines of either:
dispatchEvent( new BatchEvent("batchGenerated") );
or
dispatchEvent( new BatchEvent(BatchEvent.BATCH_GENERATED) );
The second way is usually preferred as using variables instead of magic strings gives you an extra level of compile time checking.
The first required parameter of events is typically the type of the event - Event.CHANGE (aka "change"), FlexEvent.VALUE_COMMIT (aka "valueCommit") etc.
This is what the event listener is actually comparing against.
So in your event listener code above, you would want to change the line to be either:
printableInvoice.addEventListener("batchGenerated", printableInvoice_batchGeneratedHandler);
or hopefully
printableInvoice.addEventListener(BatchEvent.BATCH_GENERATED, printableInvoice_batchGeneratedHandler);
If you want to go further, the Flex documentation goes into some detail as to how the event system works, and how the events are effectively targeted and handled through the use of the Capture, Target, and Bubble phases.

Use StyleManager.setStyleDeclaration to set button skins in Flex

I am trying to load an swf file which has button skins as images (In the library of the swf file i have given export properties which is 'TickMark') and set the skin of a flex button using StyleManager.setStyleDeclaration.
I am getting errors like 'Argument count mismatch on TickMark(). Expected 2, got 0.'
This is what i am trying to do:
private function init():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,styleSWFLoaded);
loader.load(new URLRequest("styles.swf"),new LoaderContext(false,ApplicationDomain.currentDomain));
}
private function createStyle(styleName:String):void
{
var style:CSSStyleDeclaration = new CSSStyleDeclaration(styleName);
var cls:Class = ApplicationDomain.currentDomain.getDefinition(ss) as Class;
style.setStyle("upSkin",cls);
}
}
StyleManager.setStyleDeclaration(".buttonme",style,true);
}
When I apply this new style 'buttonme' to a button i am getting below error:
ArgumentError: Error #1063: Argument count mismatch on TickMark(). Expected 2, got 0.
Not sure why is this happening, and strange thing is, when I embed the same swf file it works, like below:
[Embed(source="styles.swf", symbol="Tick")]
private var GraphicClass:Class;
If I use the class GraphicClass in setStyleDeclaration, it works... but basically I want it dynamically.
Or there are other easy methods to skin (image) a flex button dynamically?
You should be able to set your skin like that dynamically. It probably has to do with your TickMark class. I'm assuming when you do style.setStyle("upSkin", cls);, that cls is TickMark and it has two required constructor args: TickMark(arg1:Object, arg2:Object). Is that true? Somewhere in the setStyle method its doing new cls().
If so, just make sure there's no constructor arguments and it should work.
If not, try following the stack trace and using breakpoints in Flex Builder if you don't already, that should help pinpoint the problem.
Best,
Lance
I believe, when you embed the export-symbol in your flex-app, it would be taking care of size and perhaps just embedding the png directly.
As your symbol-class extends BitmapData, it has to be instantiated by passing required arguments in constructor. So whatever error you get, is by design and work as expected.
You can wrap png in some other type of symbols (sprite, movieclip, etc) and export. That should work fine when used in setStyle (..,..)

Resources