Déclencher le PASTE sans rien faire

cedriclomb Messages postés 275 Date d'inscription samedi 19 novembre 2005 Statut Membre Dernière intervention 27 avril 2010 - 27 avril 2010 à 12:22
cedriclomb Messages postés 275 Date d'inscription samedi 19 novembre 2005 Statut Membre Dernière intervention 27 avril 2010 - 27 avril 2010 à 15:10
Bonjour,

Je cherche à récupérer les données images de mon presse papier dans flash.

Voici mon code :
import com.adobe.images.*;
import com.dynamicflash.util.Base64;
import flash.desktop.Clipboard;
import flash.desktop.ClipboardFormats;
import flash.display.Bitmap;
import flash.events.Event;
import flash.display.BitmapData;


this.addEventListener(Event.PASTE,paste);

function paste(e:Event) {
var cb:Clipboard=Clipboard.generalClipboard;
//if (cb.hasFormat(ClipboardFormats.BITMAP_FORMAT)) {
var bd:Bitmap=new Bitmap(Clipboard.generalClipboard.getData(ClipboardFormats.BITMAP_FORMAT) as BitmapData);
//var ce:ClipboardEvent=new ClipboardEvent(ClipboardEvent.BITMAP_IN_CLIPBOARD,true);
//e.bitmapData=bd;

trace(bd);

var byteArray:ByteArray;
byteArray=PNGEncoder.encode(bd.bitmapData);
// convert binary ByteArray tZo plain-text, for transmission in POST data
var byteArrayAsString:String=Base64.encodeByteArray(byteArray);

// constuct server-side URL to which to send image data
var url:String='/sfEmailMeAFireShot/loadimage?'+Math.random();

trace('oo'+byteArrayAsString);

// create URL request
var request:URLRequest=new URLRequest(url);

// send data via POST method
request.method=URLRequestMethod.POST;

// set data to send
var variables:URLVariables = new URLVariables();
variables.image=byteArrayAsString;
request.data=variables;

navigateToURL(request, "_blank");

//dispatchEvent(ce);
//clear image from clipboard
//cb.clearData(ClipboardFormats.BITMAP_FORMAT);
/*} else {
trace('NO datas');
}*/
}
dispatchEvent(new Event("paste"));


Hors petit problème dispatchEvent(new Event("paste")); me retourne

SecurityError: Error #2179: L'objet Clipboard.generalClipboard ne peut être lu que pendant le traitement d'un événement flash.events.Event.PASTE.
at flash.desktop::Clipboard/getObjectReference()
at flash.desktop::Clipboard/convertNativeFormat()
at flash.desktop::Clipboard/getOriginal()
at flash.desktop::Clipboard/getData()
at capture_fla::MainTimeline/paste()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at capture_fla::MainTimeline/frame1()


Comment faire pour déclencher le paste sur un bouton ou mieu directement.

D'avance merci.

6 réponses

pegase31 Messages postés 6138 Date d'inscription dimanche 21 décembre 2003 Statut Modérateur Dernière intervention 4 septembre 2013 12
27 avril 2010 à 13:53
Bonjour, sur la doc est écris :

Remarque : dans les applications de Flash Player 10, une opération de collage à partir du presse-papiers implique tout d'abord un événement utilisateur (par exemple, utilisation du raccourci clavier de la commande Coller ou clic de souris sur la commande Coller d'un menu contextuel). Clipboard.getData() ne renvoie le contenu du presse-papiers que si InteractiveObject a reçu et exécute un événement coller. En aucun autre cas, l'appel à Clipboard.getData() ne peut échouer. La même restriction s'applique dans le contenu AIR qui se trouve en dehors du sandbox de l'application.

et plus bas, je lis ceci :

[i]Les formats standard sont :
* BITMAP_FORMAT: objet BitmapData (AIR uniquement)/i

Déjà es-tu certain de déclencher ton évènement comme précisé et ensuite es-tu en compilation AIR ?

Peg'
0
cedriclomb Messages postés 275 Date d'inscription samedi 19 novembre 2005 Statut Membre Dernière intervention 27 avril 2010 1
27 avril 2010 à 14:07
Non je suis juste en AS3

mais par contre va falloir que je sorte l'artillerie lourde JAVA, pour faire mon coller automatiquement car on ne peux d'apres la doc faire de coller sur un bouton !

Comment on fait un éditeur avec un bouton coller en flash?!

C'est pas juste, moi je voulais juste récupérer le base64 de l'image mise en presse papier !
0
pegase31 Messages postés 6138 Date d'inscription dimanche 21 décembre 2003 Statut Modérateur Dernière intervention 4 septembre 2013 12
27 avril 2010 à 14:11
Ben déjà il suffit de savoir que flash ne fonctionne qu'en 32 bits pour savoir que ton projet n'est pas fonctionnel ...

Peg'
0
cedriclomb Messages postés 275 Date d'inscription samedi 19 novembre 2005 Statut Membre Dernière intervention 27 avril 2010 1
27 avril 2010 à 14:21
Je ne suis pas sur d'avoir compris ou est le problème du 32bit pegase31 ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
pegase31 Messages postés 6138 Date d'inscription dimanche 21 décembre 2003 Statut Modérateur Dernière intervention 4 septembre 2013 12
27 avril 2010 à 14:26
ben tu veux récupérer le base64, non ?
Sachant que flash ne gère pas les 64 bits, tu ne peux pas récupérer des images codées en 64bits.

Peg'
0
cedriclomb Messages postés 275 Date d'inscription samedi 19 novembre 2005 Statut Membre Dernière intervention 27 avril 2010 1
27 avril 2010 à 15:10
Ah bah si je le recupere en octal après tout je m'en fiche php feras le reste

Mai j'ai trouvé cette classe

/*
Base64 - 1.1.0

Copyright (c) 2006 Steve Webster

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: 

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.dynamicflash.util {

import flash.utils.ByteArray;

public class Base64 {

private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

public static const version:String = "1.0.0";

public static function encode(data:String):String {
// Convert string to ByteArray
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(data);

// Return encoded ByteArray
return encodeByteArray(bytes);
}

public static function encodeByteArray(data:ByteArray):String {
// Initialise output
var output:String = "";

// Create data and output buffers
var dataBuffer:Array;
var outputBuffer:Array = new Array(4);

// Rewind ByteArray
data.position = 0;

// while there are still bytes to be processed
while (data.bytesAvailable > 0) {
// Create new data buffer and populate next 3 bytes from data
dataBuffer = new Array();
for (var i:uint = 0; i < 3 && data.bytesAvailable > 0; i++) {
dataBuffer[i] = data.readUnsignedByte();
}

// Convert to data buffer Base64 character positions and 
// store in output buffer
outputBuffer[0] = (dataBuffer[0] & 0xfc) >> 2;
outputBuffer[1] = ((dataBuffer[0] & 0x03) << 4) | ((dataBuffer[1]) >> 4);
outputBuffer[2] = ((dataBuffer[1] & 0x0f) << 2) | ((dataBuffer[2]) >> 6);
outputBuffer[3] = dataBuffer[2] & 0x3f;

// If data buffer was short (i.e not 3 characters) then set
// end character indexes in data buffer to index of '=' symbol.
// This is necessary because Base64 data is always a multiple of
// 4 bytes and is basses with '=' symbols.
for (var j:uint = dataBuffer.length; j < 3; j++) {
outputBuffer[j + 1] = 64;
}

// Loop through output buffer and add Base64 characters to 
// encoded data string for each character.
for (var k:uint = 0; k < outputBuffer.length; k++) {
output += BASE64_CHARS.charAt(outputBuffer[k]);
}
}

// Return encoded data
return output;
}

public static function decode(data:String):String {
// Decode data to ByteArray
var bytes:ByteArray = decodeToByteArray(data);

// Convert to string and return
return bytes.readUTFBytes(bytes.length);
}

public static function decodeToByteArray(data:String):ByteArray {
// Initialise output ByteArray for decoded data
var output:ByteArray = new ByteArray();

// Create data and output buffers
var dataBuffer:Array = new Array(4);
var outputBuffer:Array = new Array(3);

// While there are data bytes left to be processed
for (var i:uint = 0; i < data.length; i += 4) {
// Populate data buffer with position of Base64 characters for
// next 4 bytes from encoded data
for (var j:uint = 0; j < 4 && i + j < data.length; j++) {
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
}
      			
      			// Decode data buffer back into bytes
outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 0x30) >> 4);
outputBuffer[1] = ((dataBuffer[1] & 0x0f) << 4) + ((dataBuffer[2] & 0x3c) >> 2);		
outputBuffer[2] = ((dataBuffer[2] & 0x03) << 6) + dataBuffer[3];

// Add all non-padded bytes in output buffer to decoded data
for (var k:uint = 0; k < outputBuffer.length; k++) {
if (dataBuffer[k+1] == 64) break;
output.writeByte(outputBuffer[k]);
}
}

// Rewind decoded data ByteArray
output.position = 0;

// Return decoded data
return output;
}

public function Base64() {
throw new Error("Base64 class is static container only");
}
}
}
0
Rejoignez-nous