Flex 4 binding to mx:Image - apache-flex

Is it possible to bind a property (don't know which) of the mx:Image control, so that it is (should be) possible to get in form of a bytearray? (using Flex 4)
The reason i'm asking is this: i have to forward the bytearray to a WCF service to be stored and afterwards retrieved!
If this is not directly achievable is there a work-around ?
Thanks in advance!

If you load content into your image then when the Event.COMPLETE dispatches (on the image instance) the <imageInstance>.content.loaderInfo.bytes ByteArray holds the loaded data.

you can use BindingUtils.bindproperty to bind your object to the value of Image.source, like its described here in the docs

Related

Setting bindable value to label in Actionscript (no curly brackets in mxml)

I've got a model class with custom change events, which is working fine if I make a reference to that class in my mxml using;
[Bindable] private var firstClass:FirstClass;
The objects gets filled by a server side script, so don't worry, firstClass isn't null.
Anyhow, accessing firstClasses properties in mxml works perfectly fine using curly brackets. The binding works just as expected.
However, is there any way to access firstClasses properties and set them to say a label with pure Actionscript.
lblTest.text = firstClass.property;
The code above doesn't work. I suppose because it sets a fixed value to the label.
I'm aware of using BindingUtils.bindProperty to explicitly set the source and destination for the binding. However, this turned out to cause huge performance issues in my (mobile) application.
So is there a simpler, more efficient way to do this?
No. The BindingUtils uses propertyChanged events to detects when an object's property changes. You won't be able to bind something without listening to events, and the most painless way to do it is using BindingUtils.

passing values from 2 flex movies

I have a flex compiled swf module inside my flex program
I just need to pass it some values like I do it when I use
chat.swf?username=john : that works !
I tried it with flex swfLoader and Image
SWFLoader source="../bin-debug/chat.swf?username=john"
Image source="../bin-debug/chat.swf?username=john"
This does not work: these values are not passed !
what is the simplest way to do it ?
Regards
Load the swf up and set the variables on it normally like it was a regular object.

Flex SWFLoader Event.COMPLETE not triggering

While trying to load a Bitmap onto a SWFLoader the Event.COMPLETE event is not being triggered
mySWFLoader.source = new Bitmap(Bitmap(someEvent.content).bitmapData);
but if I use a URL as source the complete event is triggered:
mySWFLoader.source = "http://example.com/123.jpg";
Is there some kind of restriction while using Bitmap as source?
I believe if you use data that already exists in memory (which your Bitmap would) then no load operation would happen. It should be usable immediately after construction. I know attaching movies in AS2 worked like that. If it was part of the library you could use it right away and no loading events would happen.
Use
mySWFLoader.addEventListener(Event.ADDED,handleSwfLoadComplete);
It fires when the content is actually created and added to the display list.
I encountered the same issue. The problem is that when you use Bitmap or Class as source, the content is populated only after the Bitmap or class was instantiated.
This happens in swfLoader.loadContent which eventually adds the newly created content to the displayList as the loader's child, and eventually dispatches the ADDED event.

Displaying content from bulkLoader which is typed as MovieClip in Flex app

I know this is somehow trivial, but I couldn't find appropriate solution so please help me :)
I am using bulkLoader to load dozens of SWFs into my Flex app, and all of SWFs are static (1 frame only). 'Everything' works fine, however, I'm not sure how to handle data from bulkLoader... I am getting MovieClip types for all of my SWFs, and I am not sure how to tell to Image or SWFLoader classes to use some of those MovieClips as source...
Thanks for any help really :)
m.
The source property of the Image or SWFLoader class only stores the location of the file (URL or local path) as a string. If you set this property the class tries to load that file (with bindable blabla)
So, you can't overwrite the source property with a movie clip.
Maybe you could cast the MovieClip to an Image component using
var image:Image = bulkLoaderMovieClip as Image;
bye,
tux

Flex component access other component

I have 2 components for example (editor.mxml using mx:windows), when I click an edit button, I want to get the current value from the other component's datafield? (datagrid.mxml using mx:window)
I do know how to access the main MXML's datagrid by parentDocument or Application.application method, but stumped block if I want to access other way as mentioned above. Keep the code as simple as possible.
You could either do dependency injection, that is, give component A a reference to component B so that they can communicate directly (example of tighter coupling,) or have both components communicate through a common mediator using events (example of more loose coupling.)
Both of those options would be implemented wherever it is that you're creating those components (A and B in this example) and adding them to the display list.
This might be more complicated than it deserves, and it smacks of Pattern-Fever, but you could use a mediator class that listens for the CLICK event from the button and knows enough about the other component to query its property. It could even transmit that data using a custom event, which the button listens for.
While this involves three classes instead of two, it often turns out to be easier to have two components that focus on looking good and one that worries about coordination.
Cheers
Try this:
FlexGlobals.topLevelApplication
This points Your root. From the root You can grab every element You want.
You can also add an id to the custom component like this,
<custom:Editor id="myCustomComponent">
</Editor:AddressForm>
and
access your datagrid's value like this,
var data:ArrayCollection = myCustomComponent.DatagridID.dataProvider;

Resources