Drag & drop of files from the file system into Flex doesn't work - apache-flex

I am trying to implement drag & drop of files from the file system into Flex, but somehow it doesn't work.
To be precise, it refuses to register when the nativeDragEnter event happens, meaning, it doesn't do anything when i drag a file system file into a component. I tried it with mx and spark components, using flex 3.6A and 4.10 but nothing works.
I am working on Windows 8.1. Could this be the problem?
Below is what i did, did i miss something?
<mx:Script>
<![CDATA[
protected function hbox1_nativeDragEnterHandler(event:NativeDragEvent):void
{
var a:String = "segdfsh";
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%" nativeDragEnter="hbox1_nativeDragEnterHandler(event)">
</mx:HBox>

The code in the question seems to work after all, but for some reason it didn't work if i debug it from Flashbuilder, but when i release my project, then it works like a charm, so yeah, no issue here, i guess.

Related

Drawable Canvas

I recently upgraded my Flash Builder from Burrito to 4.5 Premium. I am trying to create this (Drawing Demo) in the latest version of Flex, on Blackberry Playbook, but I am getting errors:
Code
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:Panel layout="absolute" title="Draw Test" backgroundColor="#ffffff">
<mx:Canvas backgroundColor="#ffffff">
<mh:DrawableCanvas id="main" backgroundColor="#ffff80" backgroundAlpha="0" width="100%" height="100%" y="0" x="0">
</mh:DrawableCanvas>
</mx:Canvas>
</s:Panel>
</s:Application>
The Error
The prefix "mx" for element "mx:Canvas" is not bound. I have tried adding "xmlns:mx="http://www.adobe.com/2006/mxml" to the head with no joy.
Is canvas no longer supported? All I want is a canvas to draw onto to capture a human signature...
Any ideas?
EDIT:
Took onboard the advice but still getting something wrong, see screenshot.
Any ideas? Am I missing a mx.swc or something?
Canvas and all other components are still supported since Flex4 is backwards compatible with Flex3.
In your case, the error message says it all.
Your application does not correctly refer to the mx: namespace.
Therefore, it will not be able to find the Canvas component.
In a Spark application, it is advised to add the mx namespace as follows:
xmlns:mx="library://ns.adobe.com/flex/mx"
instead of
xmlns:mx="http://www.adobe.com/2006/mxml"
If your are migrating your Flex3 Halo application to a Flex4 Spark application, please read the official migration guide. Chapter 4 is particularly useful.
Cheers
Make sure that your project can use both MX and Spark components in Properties -> Flex Build Path
Move caret to the end of <mx:Canvas and press Ctrl + Space. IDE should suggest correct namespace.

Creating First Application of Flex "How to Change Button label", learning resources for Flex from Flash background

I'm just getting started switching from flash to flex for the better components. I am trying the simple experiment of adding a button and then changing the label. This code does not work. It does not recognize myButton. In flash I could access a button instance after adding it using the instance name. Can't you do this in flex?
Thanks
<s:Button x="50" y="42" label="Button" id="myButton"/>
<fx:Script>
<![CDATA[
myButton.label="winning";
]]>
</fx:Script>
Flex have an Event based structure you can not just put command/expression in script block
it should be wrapped in function
like
private function changelabel():Void
{
myButton.label="winning";
}
and you need to call this function on an event like Click event of Button as
<s:Button x="50" y="42" label="Button" id="myButton" click="{changelabel()}"/>
You should read Migrating a Flash application to Flex
and to take a look in Flex you should vist Flex Developer Center
Hopes that helps

Programmatically add character to TextInput when Hiragana IME is active

I'd like to be able to add a character to a TextInput programmatically (say when you press a button) even when using IMEs (I'm using a Japanese IME right now). Normally this would be super easy, i.e.
protected function button_clickHandler(event:MouseEvent):void
{
ti.text = "k";
}
where ti is a TextInput component. However, things get a little tricky when using an IME. The code above, for instance, adds a k in ti even if you're using the Hiragana IME.
I looked at the IME documentation and tried something like this
protected function button_clickHandler(event:MouseEvent):void
{
IME.setCompositionString("k");
}
at first I thought this was doing the trick, but it seems like it always defaults to what looks like Half-Width Katakana (although I'm not 100% sure), even if the Hiragana conversionMode is currently selected, or if I set it right before setting the composition string. Unfortunately the IME library doesn't seem to be open source so I have no idea if this is a bug or not.
Was wondering if anyone had any advice - I realize this is super specific so the odds are low, but thought I'd try.
thank you!
post-edit: here is some code to try out what I'm talking about. Note: you'll need Japanese IME setup on your machine. I'm using this on a Windows 7 box with Japanese IME setup, and running it on standalone Flash. It's hard to see the difference between typing a k in Hiragana and in Katakana, but if you look closely you should notice a difference (and if you type an 'a' right after you should see different results popping up).
<?xml version="1.0"?>
<!-- dpcontrols/adg/SimpleADG.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
protected function button_clickHandler(event:MouseEvent):void
{
ti.setFocus();
try
{
IME.enabled = true;
IME.conversionMode = IMEConversionMode.JAPANESE_HIRAGANA;
IME.setCompositionString("k");
}
catch (error:Error)
{
trace("Unable to set conversion mode.\n" + error.message);
}
}
]]>
</fx:Script>
<s:VGroup>
<s:TextInput id="ti"/>
<s:Button label="go" click="button_clickHandler(event)"/>
</s:VGroup>
</s:Application>
First, look at this link: http://livedocs.adobe.com/flex/3/html/help.html?content=18_Client_System_Environment_6.html
Make sure you have IME enabled and the proper settings. Second, what version of flex are you using? Do you have a font that's loaded into the application that can handle the language?
filed a bug - we'll see what Adobe says.

AIR: Security Sandbox Violation when using remote images

The code below is simplified for example
I'm developing an AIR application (using Flex) which loads several of its images from a remote web server. The images display fine, however, whenever I'm manipulating the containers which hold the remotely-loaded images, I get errors in my console:
*** Security Sandbox Violation ***
SecurityDomain 'http://www.google.com/intl/en_ALL/images/logo.gif' tried to access incompatible context 'app:/sandbox_test.swf'
The images don't seem to be affected, but I don't like having errors displayed that I don't understand. Here's a sample app that exemplifies the problem:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication width="500" height="500" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HDividedBox width="100%" height="300" horizontalCenter="0" verticalCenter="0" backgroundColor="#000000" liveDragging="true">
<mx:Image source="http://sstatic.net/so/img/logo.png"/>
<mx:Image source="http://www.google.com/intl/en_ALL/images/logo.gif"/>
</mx:HDividedBox>
</mx:WindowedApplication>
If you drag using the dragger on the HDividedBox, the security error appears.
I've looked at some of the Security class / security sandbox stuff for AIR, but by default AIR should have access to networked resources (which is why the images load I think). Using Security.allowDomain("www.google.com") isn't an option in AIR - it just throws a SecurityError.
Does anyone know what's causing it, or how to fix it? (Or maybe it's just a Flex/AIR bug?).
Also - does anyone know if there's a way to break when the error happens, so I can trace it to the root action causing it?
This security sandbox issue is specific to dragging UIComponents that have Image components in them. The Image components reference external images. I've looked everywhere and every post I run into the thread ends unanswered, which typically means its a bug.
My bootleg workaround? After the image has downloaded to the Image component, cache it as a bitmap and reassign the Image components source to the Bitmap. This fixed the issue for me:
private function authorImageLoadComplete(event:Event):void {
var bp:Bitmap = dupeImage(authorImage);
authorImage.source=bp;
}
private function dupeImage(source:Image):Bitmap {
var data:BitmapData = Bitmap(source.content).bitmapData;
var bitmap:Bitmap = new Bitmap(data);
return bitmap;
}
Then your image tag in your UIComponent:
<mx:Image id="authorImage" complete="authorImageLoadComplete(event)"></mx:Image>
Best of luck guys
For Flex 4, try setting the top level WindowedApplication's useNativeDragManager property to false, as documented here: http://cookbooks.adobe.com/post_How_do_you_make_a_Spark_custom_itemRenderer_with_a-16532.html
Do this images show up when you aren't running in Debug? The problem is that the domain doesn't have a crossdomain.xml file setup to allow for images in Flash.
http://www.google.com/crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="by-content-type" />
</cross-domain-policy>
You should probably just grab the images and place them in your application's assets, or on a domain you control and can properly add a crossdomain.xml that would allow for the content. Security.allowDomain isn't going to have the affect you are looking for. This article has the best explanation of crossdomain security I have read.
See ryanstewart's comment below. The above is hogwash for an AIR app.

How to create a Flex Display component in Flash?

I have used Flash to make skins, which I import and apply to Flex components.
But how can I create a component in Flash, with properties and methods. And make it able to be added to the displayList in a Flex app?
I installed the Flex component kit for flash. Created my component in flash (it extends MovieClip). Did Command->Convert to flex Component, did File->Published, which gave me a .swc, dropped the .sec file into my Flex project. Now when I create a new var the class "FlashFlexComponentTest" pops up in the new class hint box, so flex sees it. But afterwards I get the error:
Type was not found or was not a
compile-time constant: FlashFlexComponentTest
I feel like I must be missing a step?
Thanks!
UPDATE
I added the .swc via project build path -> add SWC.
I no longer have a compile-time error but I am getting a runtime error:
Type Coercion failed: cannot convert FlashFlexClassTest#9089129 to mx.core.IUIComponent
The base class for all flex components, UIComponent, allows you to add Sprites that don't implement the IUIComponent interface.
An example :
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="init();">
<mx:Script>
<![CDATA[
private function init():void
{
var component:FlashFlexClassTest = new FlashFlexClassTest();
container.addChild(component);
}
]]>
</mx:Script>
<mx:UIComponent id="container" width="100%" height="100%"/>
</mx:Application>
There's a good video tutorial on this at Linda.com by David something. I did a lot of this a year or so ago, and that was the best resource I found. Doesn't cover absolutely every possible angle, but does a great job of covering what you need to know.
I'm guessing there's just some small linkage detail that you're missing. The tutorial should get you straight, if that's the case. It was worth the $20, or whatever, for a monthly subscription for me.
Sorry, that's the best I can do... haven't built Flex components in Flash since last year.
basically there are step what need to do:
open Flash
drag a component you need to stage
right click on it in Library > Export to SWC
put this SWC in your Flash Builder libs folder
There is explanation by Jesse Warden http://jessewarden.com/2011/06/integrating-flash-components-with-flex-revisited.html
Cheers!

Resources