Why are there two different HTTPService classes in Flex?
this
and
this
And the second one inherits the first one.
Why couldn't there be a single class combining the two?
One of the objects (the first link you posted) is the HTTPService Object itself.
The second is the object that wraps the HTTPService object and gives it the additional functionality for the <mxml /> tag.
The two probably weren't combined because you don't necessarily need the implementation of the IMXMLObject and IMXMLSupport interfaces every time you need an HTTService object.
mx.rpc.http.mxml.HTTPService can also handle concurrency while the other can't.
Edit:
Although in the online documentation I see concurrency as a property of both, several sources say thats not true(and my tests didn't work when I first tried using it). Also the concurrency package is only imported into the mxml.HTTPService, not the base rpc class.
Bug Comment
Mederator comment on the docs page
There appear to be more error handling features in the URLLoader class. Using MXML to create your HTTPService is not a big difference though.
// ActionScript Style
private function myService():void {
var service:HTTPService = new HTTPService();
...service.parameters = value;...
service.send();
}
or
< !-- MXML Style -- >
< mx:HTTPService >
...< parameters >...
< /mx:HTTPService >
The first is a member of the mx.rpc.http package and is used in ActionScript code. The other version of the HTTPService class is a sublass of the first and is a member of the mx.rpc.http.mxml package. This is the version you use when you instantiate the object with the tag.
The versions are nearly identical with two significant differences: only the MXML Version implements the showBusyCursor property, which casuses an animated curser top be displayed for the duration of an HTTPService request/response cycle, and the concurrency property, which determines how multiple concurrent requests to the same network resource are handled.
The concurrency property isn't implemented in the version of the HTTPService class typically used in ActionScript because, when using ActionScript you commonly create a new HTTPService object for each new request.
Source: Adobe Flex 3 Bible - David Gassner
Related
How can i access a variable or change the state of an element(like tabNavigator) from one mxml to another mxml in FLEX 4.6??
Each separate MXML file should be viewed as a class, since that is what they are.
In the theory of encapsulation; two classes should not directly access / change each others variables or state. They should use an API provided by the developer of the MXML Class.
If MXML 1 is the parent of MXML 2; then MXML1 can pass data to MXML2 by setting public properties or calling public methods.
MXML2 can pass data to MXML1 by dispatching events.
If MXML1 and MXML2 are not in a parent child relationship; (AKA Both children of the same component as one example) they they should not communicate with each other directly. They should dispatch events which the mutual parent should handle and use to set values or execute methods on it's own children.
From an encapsulation standpoint, that is how it should be done using the built in facilities of ActionScript / Flex.
What a lot of people do as part of building applications is to make use of dependency injection. That was values that are "global to the application" can be shared among multiple components. Another approach to doing this is to use a Singleton. A third approach might be to make use of static values on a class; which can be accessed without accessing an instance of a class.
I'm trying to use Webservice component in my Flex 4 application.
I need to use this in Actioncript and not using MXML tags.
I'm able to invoke the WSDL operations successfully, but the resultFormat is Object by default.
How do I set it to e4x?
var lookupService:WebService = new WebService();
lookupService.wsdl =url;
lookupService.loadWSDL();
lookupService.doLookup.addEventListener(ResultEvent.RESULT, lookupResultHandler);
lookupService.doLookup.addEventListener(FaultEvent.FAULT, faultHandler);
lookupService.doLookup(lookupString);
I tried to set the format by
lookupService.resultFormat = "e4x";
But this is not working. The calls are not even going through when I do this.
Can you please provide your suggestions for implementing this using AS3?
If you take a look at the two web service classes, you'll realize that resultFormat is not a property on either of them. Resultset is a property on the operations array.
If that doesn't help, you'll have to quantify "not working." What isn't working? Are you getting compile errors? Are you getting runtime errors? IS the data not being returned? Is the data not be returned as XML?
You'll probably have to set this up in MXML and dissect the generated ActionScript to figure out the appropriate AS3 syntax.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/soap/WebService.html
i have in my flex application various mxml components that all need to show stats based on the same data. how can i go about doing that? do i need some mvc framework like cairngrom or puremvc for that or can i do it without them?
any design ideas?
You don't need any framework for that. Do you know about data-binding?
http://www.flexafterdark.com/docs/Flex-Binding
This way you can set your data as dataprovider for many components. For example to show your data in dataGrid you set in mxml it's attribute
dataProvider="{yourDataArrayCollectionIdentifier}"
and in your arrayCollection declaration you need to set metatag [Bindable]
[Bindable] var yourDataArrayCollectionIdentifier : ArrayCollection;
there are other datatypes you can use as dataprovider, just arrayCollection is the most common
There are a handful of approaches to this. For encapsulation purposes, you should isolate your shared data out into a separate class; possibly a Value Object although it does't have to be.
Then create a public variable property in each MXML Component of this classes type. When you create the instance of each mxml component, pass in your 'global' instance of the data class.
You don't need to use an MVC framework, but the Cairngorm Model Locator could also be used to address this problem. The Model Locator is a singleton. You'd store your data inside the singleton instance; and then each MXML Component would reference the singleton for the data. Creating an external dependency like this breaks encapsulation, though. I much prefer the parameter passing route for non-application specific components.
package
{
public class ApplicationViewModel
{
[Bindable] public var message:String = "";
}
}
You can now use this message across your MXML where you make the instance of that.
A singleton class is used in different scenarios where you want to hold some information of all states. A better example would be Chess Board, where your board is Singleton class and its state should never change as you have to keep track of all coins moved across the board and its position.
You are injecting this message variable in the views where you want to show the data.
I'm re-writing an MXML item renderer in pure AS. A problem I can't seem to get past is how to have each item renderer react to a change on a static property on the item renderer class. In the MXML version, I have the following binding set up on the item renderer:
instanceProperty={callInstanceFunction(ItemRenderer.staticProperty)}
What would be the equivalent way of setting this up in AS (using BindingUtils, I assume)?
UPDATE:
So I thought the following wasn't working, but it appears as if Flex is suppressing errors thrown in the instanceFunction, making it appear as if the binding itself is bad.
BindingUtils.bindSetter(instanceFunction, ItemRenderer, "staticProperty");
However, when instanceFunction is called, already initialized variables on the given instance are all null, which was the cause of the errors referenced above. Any ideas why this is?
You have 2 options that I am aware of:
Option 1
You can dig into the code that the flex compiler builds based on your MXML to see how it handles binding to static properties. There is a compiler directive called -keep-generated-actionscript that will cause generated files to stick around. Sleuthing through these can give you an idea what happens. This option will involve instantiating Binding objects and StaticPropertyWatcher objects.
Option 2
There is staticEventDispatcher object that gets added at build time to classes containing static variables see this post http://thecomcor.blogspot.com/2008/07/adobe-flex-undocumented-buildin.html. According to the post, this object only gets added based on the presence of static variables and not getter functions.
Example of Option 2
Say we have a class named MyClassContainingStaticVariable with a static variable named MyStaticVariable and another variable someobject.somearrayproperty that we want to get updated whenever MyStaticVariable changes.
Class(MyClassContainingStaticVariable).staticEventDispatcher.addEventListener(
PropertyChangeEvent.PROPERTY_CHANGE,
function(event:PropertyChangeEvent):void
{
if(event.property == "MyStaticVariable")
{
someobject.somearrayproperty = event.newValue as Array;
}
});
I think you need to respond to the "PropertyChanged" event.
If you're going to do that, use a singleton instead of static. I don't think it will work on a static. (If you have to do it that way at all, there are probably a couple ways you could reapproach this that would be better).
var instance:ItemRenderer = ItemRenderer.getInstance();
BindingUtils.bindProperty(this, "myProperty", instance, "theirProperty");
After fiddling with this for a while, I have concluded that this currently isn't possible in ActionScript, not even with bindSetter. It seems there are some MXML-only features of data bindings judging by the following excerpt from the Adobe docs (though isn't it all compiled to AS code anyways)?
You cannot include functions or array
elements in property chains in a data
binding expression defined by the
bindProperty() or bindSetter() method.
For more information on property
chains, see Working with bindable
property chains.
Source: http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_7.html
You can create a HostProxy class to stand in for the funciton call. Sort of like a HostFunctionProxy class which extends from proxy, and has a getProperty("functionInvokeStringWithParameters") which will invoke the function remotely from the host, and dispatch a "change" event to trigger the binding in typical [Bindable("change")] Proxy class.
You than let the HostProxy class act as the host, and use the property to remotely trigger the function call. Of course, it'd be cooler to have some TypeHelperUtil to allow converting raw string values to serialized type values at runtime for method parameters (splitted by commas usually).
Example:
eg.
var standInHost:Object = new HostFunctionProxy(someModelClassWithMethod, "theMethodToCall(20,11)");
// With BindingUtils.....
// bind host: standInHost
// bind property: "theMethodToCall(20,11)"
Of course, you nee to create such a utlity to help support such functionality beyond the basic Flex prescription. It seems many of such (more advanced) Flex bindings are usually done at compile time, but now you have to create code to do this at runtime in a completely cross-platform Actionscript manner without relying on the Flex framework.
I'm working on an Flex application which uses many objects, e.g. LEDs, bulbs, gauges created in Flash. The objects internally consist of several small MovieClips and have their own logic inside. One of the initial requirements was that the objects have to be loaded at runtime, thus they were exported as SWF, not SWC. However, we ran into problem when we tried to duplicate loaded SWF. It turned out that MovieClip class doesn't have neither copying constructor nor method that would allow us to clone existing MovieClip. This way we'd end up loading an object every time from hdd, which involves a lot of overhead. Is it possible that language like ActionScript 3 doesn't have such a mechanism? Have we missed something out? If not, am I correct that the only solution is to use Flash Component Kit, make some custom components and include them as SWC at compile time?
After you load the MovieClip is it possible to use getDefinitionByName() as shown here?
http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getDefinitionByName()
You are correct in that there is no built in way to duplicate a movieclip.
There are however work arounds. The esiest way as I see it is to give the movieclips classes.
You don't have to make the actual classes. Just write any name in the class field when setting up linkage on the top most movieclip that needs to be copied.
So a name for you LED movieclip, another name for the bulb etc.
The benifit is that now you have a class that you can initiate objects from.
No when you grap one of the movieclips you can duplicate it with the following method:
public function DuplicateDisplayObject(dO:DisplayObject):DisplayObject
{
if(dO == null)
return null;
var dOClass:Class = Object(dO).contructor;
return DisplayObject(new dOClass());
}
This assumes of cause that you can actually get a hold of one of the movieclips first. And mind you that it doesn't copy the state of the movieclip.
Another more importent note is that this only works if the you link the movieclips to classes. The classes doesn't have to exist (flash will create empty classes for you).
Other solutions could be:
Compiling against the classes without
including them (see the
"external-library-path" tag for the
flex compiler), and load the them at
runtime (from swf).
Compiling against the classes as a
RSL (Runtime Share Library) the swc
will be loaded at runtime.
Adobe has more info on how to do that, should be easy to find on their website.
A more exotic solution would be copy the bytecode of an object. Not sure if that would work with something on the displaylist, properly not.
About the solution using getDefinitionByName():
If I remember correctly you still need to give the movieclips fake classes, since getQualifiedClassName only returns MovieClip class. But I could be wrong.
Another solution:
private function duplicateImg(sourceLoaderInfo:LoaderInfo, target:Image):void
{
var ba:ByteArray = sourceLoaderInfo.bytes;
var dupCliploader:Loader = new Loader();
dupCliploader.contentLoaderInfo.addEventListener(
Event.COMPLETE, bytesLoaded);
dupCliploader.loadBytes(ba);
}
private function bytesLoaded(event:Event):void
{
var mc:MovieClip = event.currentTarget.content as MovieClip;
_img.source = mc;
_img.width = mc.width;
_img.height = mc.height+5;
}