my code works on localhost,but not on the server,what could be the problem?I also want to return some string back from php to flex app but I can't solve that.
Here is my code :
[Bindable]
public var encodedString:String;
[Bindable]
public var img_name:String;
[Bindable]
public var pid:int;
[Bindable]
public var url_string:String;
protected function btn_save_clickHandler(event:MouseEvent):void
{
var bmpData:BitmapData = new BitmapData(videoDisplay.width,videoDisplay.height-25);
bmpData.draw(videoDisplay);
var bm:Bitmap = new Bitmap(bmpData);
img.source = bm;
var jpg_e:JPEGEncoder = new JPEGEncoder();
var bytes:ByteArray = new ByteArray();
bytes = jpg_e.encode(bmpData);
var b64e:Base64Encoder = new Base64Encoder()
b64e.encodeBytes(bytes);
encodedString = b64e.flush();
}
protected function btn_save_image_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
save_img.send();
}
<mx:request xmlns="">
<img_data>
{encodedString}
</img_data>
<image_name>
{img_name}
</image_name>
<post_id>
{pid}
</post_id>
</mx:request>
</mx:HTTPService>
When click save,I want to save snapshoot from videodisplay to img.Also I send image to php,and want to get simple text answer that is done,but I always get object returned.
and I save image with php,and just print message,like this :
print "this is message!";
I think the problem is when I need to save image from control(video display) to image control,but this problem only occure on server but not on localhost
You need to change the last line from:
str = b64e;
To:
str = b64e.toString();
Note that calling toString() will clear the b64e object.
Update:
Let's try placing the video in a container, and then doing the .draw() on that, we'll add some additional content to it so that we can get that if the video doesn't show up.
<s:Group id="videoContainer">
<mx:Label text="Hello" />
<mx:VideoDisplay id="videoDisplay" />
</s:Group>
Hopefully you are already doing the VideoDisplay part of this, and you can update your code to add the containing group.
When you do the .draw() use videoContainer instead of videoDisplay ie. :
bmpData.draw(videoContainer);
This is just to test, if there is a sandbox issue, which it defintely seems to be, only "Hello" will show up in the bitmap, and the video will still not be seen.
Where does that video come from? Camera? FMS?
It might be either a crossdomain issue or something related to FMS (or another streaming server).
This post could help you : How do I specify a crossdomain policy file to allow Flash to grab a bitmap from an RTMP (Wowza) video stream?
Related
This php code decodes the secret key before hashing with SHA 512
$API_SECRET_KEY="W0+m0Dc9GMN9yDVeq3GMDsJ49WasEhQHkNHNuDw3wNg=";
$BDAPI_SECRET_KEY=base64_decode($API_SECRET_KEY);
$HMAC_SIGN = base64_encode(hash_hmac('sha512',$MESSAGE,$BDAPI_SECRET_KEY,true));
echo $HMAC_SIGN;
BfVNi21gY09c8M18cWBRBgo1W9pAlXM99ZVoF7Kz2ETFnIuvXjj8NRvRgn/GaT/m6YJ8efsr5s9EDbIhznAaag==
I want to replicate this in google app script
var Secret = "W0+m0Dc9GMN9yDVeq3GMDsJ49WasEhQHkNHNuDw3wNg="
var BDSecret= Utilities.base64Decode(Secret)
var hmac = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, message, BDSecret ));
Logger.log(hmac)
ew5KhLWSJixn8zw4s6VkpYIwvGBjrmjY3LhNWZr9CVEw6W22LOGg+lVzA3uQgOVyICSCffw2bzTepnBdoYtldw==
If I do not decode the API before hashing they return the same result. But for this particular purpose, the key needs to be decoded. The message variable is just my first name "Parit" in case someone wants to replicate.
I thought that Utilities.computeHmacSignature() might not be able to use []byte for the value. So as a workaround, how about using jsSHA? I think that in your case, you can use https://github.com/Caligatio/jsSHA/blob/master/src/sha512.js.
The flow for using jsSHA is as follows.
Flow :
Download sha512.js.
On script editor, create new script as for example, the filename of sha512.js.
Copy and paste the script of sha512.js to the created script.
Copy and paste the sample script to Code.gs of the script editor.
Run myFunction() of the sample script.
Sample script :
function myFunction() {
var message = "Parit";
var secret = "W0+m0Dc9GMN9yDVeq3GMDsJ49WasEhQHkNHNuDw3wNg=";
var obj = new jsSHA("SHA-512", "TEXT");
obj.setHMACKey(secret, "B64");
obj.update(message);
Logger.log(obj.getHMAC("B64"))
}
Note :
When I tested Parit for message, I got BfVNi21gY09c8M18cWBRBgo1W9pAlXM99ZVoF7Kz2ETFnIuvXjj8NRvRgn/GaT/m6YJ8efsr5s9EDbIhznAaag==.
It this was not useful for you, I'm sorry.
Update :
By the Google's update at June 19, 2018, Utilities.computeHmacSignature() got to be able to use the byte arrays. By this, using only native Google Apps Scvript, the result can be retrieved without using jsSHA. So I would like to update my answer.
Modified script :
function myFunction() {
var message = "Parit";
var secret = "W0+m0Dc9GMN9yDVeq3GMDsJ49WasEhQHkNHNuDw3wNg=";
var value = Utilities.base64Decode(Utilities.base64Encode(message));
var key = Utilities.base64Decode(secret);
var out = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, value, key);
var res = Utilities.base64Encode(out)
Logger.log(res)
}
Result :
BfVNi21gY09c8M18cWBRBgo1W9pAlXM99ZVoF7Kz2ETFnIuvXjj8NRvRgn/GaT/m6YJ8efsr5s9EDbIhznAaag==
Picture of tested code / Picture of working signature Hello I am using behat with the selenium driver integrated with mink and I am trying to write a test that inputs a fake signature. We use the mouse to draw the signature on the screen so I want to be able to have selenium do that for me. I tried grabbing the Id of the field and using dragTo('another element on my page'), but it only clicks inside the signature box and doesnt do anything else.
The framework I am using is laravel for php.
$field = $this->getSession()->getPage()->findById('ctlSignature);
$field->dragTo('another id on my page');
This does not work.
If I can tell the mouse to click then move 10 pixels to the right then click again that would be perfect as I can use that to draw a signature.
Thank you for the response but when I run this code I get a error,
$script = "var c = document.querySelector('#ctlSignature'); var ctx = c.getContext('2d'); ctx.moveTo(20,20); ctx.lineTo(50,50); ctx.stroke()";
$this->getSession()->evaluateScript($script);
Sends a error back Unexpected token var. If i try to use inside the string it sends another error saying unexpected token
The solution would be to use a javascript that you can execute with evaluateScript or executeScript.
$this->getSession()->evaluateScript($script);
The $script variable is a string that could contain a script like:
var c = document.querySelector("canvas");
var ctx = c.getContext("2d");
ctx.moveTo(20,20);
ctx.lineTo(50,50);
ctx.stroke();
If needed you can change the values of the draw by using variables.
Tested in the browser so it works, what you need to make sure is to switch to the iframe that contains the canvas, if any.
Please see bellow step with same script but slightly changed to write text:
/**
* #Then /^signature test$/
*/
public function signatureTest(){
$script = 'var c = document.querySelector("canvas"); var ctx = c.getContext("2d"); ctx.fillStyle = "black"; ctx.font = "20px Georgia"; ctx.fillText("automation user",10,90);';
$this->getSession()->executeScript($script);
}
Make sure the selector used will select the canvas element type.
Second version, try mousedown event trigger.
/**
* #Then /^signature test$/
*/
public function signatureTest(){
$function = <<<JS
(function(){
var c = document.querySelector("canvas");
event = document.createEvent('MouseEvent');
event.initEvent('mousedown', true, true);
var ctx = c.getContext("2d");
ctx.fillStyle = "black";
ctx.font = "20px Georgia";
ctx.fillText("automation user",10,90);
c.dispatchEvent(event);
})()
JS;
$this->getSession()->executeScript($function);
}
I'm trying to delete a data from my database with ActionScript 3.
I've created a php on my server :
<?php
include ("shared/connect.php");
$idToDelete = $_POST['idToDelete'];
$result = mysqli_query($conn,"
DELETE FROM `annoncesNew` WHERE id=$idToDelete");
?>
Then I have to send the variable idToDelete to this php in order to delete the entry.
So I did :
deleteBtn.addEventListener(MouseEvent.CLICK, deleteThisAnnonce);
function deleteThisAnnonce(event:MouseEvent):void {
trace("deleteThisAnnonce");
var variablesDelete:URLVariables = new URLVariables();
var varDelete:URLRequest = new URLRequest("http://www.***com/***/deleteAnnonce.php");
varDelete.method=URLRequestMethod.POST;
varDelete.data=variablesDelete;
var varLoaderDelete:URLLoader = new URLLoader;
varLoaderDelete.dataFormat=URLLoaderDataFormat.VARIABLES;
varLoaderDelete.addEventListener(Event.COMPLETE,completeHandlerDelete);
ValidateAndSendDelete();
function completeHandlerDelete(event:Event):void{
trace("Data Sent");
}
function ValidateAndSendDelete():void{
trace("deleting"+item.id); //item.id is my the ID. When I trace the output is 144 so it's good.
variablesDelete.idToDelete = item.id;
varLoaderDelete.load(varDelete);
}
}
So, with this code, it's supposed to delete the data where id = 144. But I've got this error when click on the deleteBtn : Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs..
(all the traces are working correctly but my data isn't delete).
I've tried my php by changing DELETE FROMannoncesNew WHERE id=$idToDelete");withDELETE FROM annoncesNew WHERE id=144"); and execute it on my webbrowser and it worked (the line with the id 144 was deleted).
Weirdly, the line is delete with my AS3 code (so the code is working) but it throws this error 2101 anyway. Any idea why ?
Thx
I believe the problem is not in your AS3 code but that your PHP script is not returning any values back to Flash. Try to add this to your PHP script:
echo "Status=true";
And you might need this in your AS3:
varLoaderDelete.dataFormat = URLLoaderDataFormat.TEXT;
I'm trying to have the background image of the body of my page change every (approximatly) N seconds. For this i have a PHP function that echoes random image src when i call it using AJAX. I then replace the current body background image src by this newly generated one, but i can't get it to work.
Here is the code, is there anything wrong in it ?
(function($) {
var $body = $('body');
window.setInterval(function() {
$.ajax({
url: 'http://localhost/some_path/index.php?exec=getNewBkgImgSrc',
}).done(function(data) {
var newImage = new Image();
newImage.onload = function() {
$body.css('background-image', newImage.src);
};
newImage.src = data;
});
}, 5000);
})(window.jQuery);
And the PHP function which does work :
public function getNewBkgImgSrc() {
echo CONTENT_URL_DIR.'/Wallpapers/wallpaper ('.rand(1, 20).').jpg';
}
Could this be because i'm using localhost ? I can mremeber having AJAX problems before when i was developping locally.
EDIT : A clue maybe is that the style property of the body element doesn't sseem to change / be set in Firebug. I also tried $('body').first() and $(document.body) and using url("") (in the value of background-image property) but it doesn't work either. The onload event does fire however.
Thanks for your help.
Why are you creating a new image object if you are getting a URL back from PHP? Just set the background-image property of body to:
$body.css('background-image', "url('" + data + "')");
If using vanilla JS:
document.body.style.backgroundImage="url('" + data + "')";
See proper format for that property here: http://www.w3schools.com/cssref/pr_background-image.asp
might need to cache bust the ajax call. Try changing the url property of the ajax call to
'/some_path/index.php?exec=getNewBkgImgSrc&cb='+((new Date).getTime()).
I have not good sense about var $body = $('body');
use $('body').css('background-image', newImage.src);
Ok, here is the think. I have a very simple flash program code in AS3, inside this program there is a dynamic textfield html capable. Also i have a database were i will put some information.
Each element in the database can be linked to other. For example, this database will contain tourist spots, and they can be related with others in the same database.
Ramdom place 1
This interesting spot is near <link to="ramdo2">ramdom place2</link>. And so, so so...
The information in the database is retrived by the flash application and it shows the text on the dynamic textfield. I need somehow to tell my flash application that have to be a link to other part of the database, so when the user click the link a function in flash call this new data.
The database is a simple Mysql server, and the data is not yet in there, waiting for your suggestions of how to format it and develop the solution.
Im a php developer too, so i can make a gateway in PHP to read the MySQL and then retrive some format to flash, an XML for example.
check text events in flash :
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html
scroll the page till events and look at the link event , it will help you trigger an event when you click a html like then you have to write an event handler to handle actions
Here's what I'd do:
Gather all your data together:
$data=array();
while($row=mysql_fetch_row($rlt))
$data[$row['id']]=$row;
printf('<script type="text/javascript">function getData(){return %s}</script>',
json_encode($data));
If you need data from multiple tables (ie one for rows and one for relations), just vary the code above so all the info you need is encapsulated in a single array.
Then in your AS3, get the data using flash.external.ExternalInterface:
data=ExternalInterface.call("getData");
Trace data to see what you have to work with. It'll be your PHP array in dot formation, just like JS.
This method is better than using XML in every way - less processing, simpler to code, less bandwidth etc.
Edit Apparently this app doesn't run in a browser. In which case, this solution is useless. Back to plan A - use XML:
header('Content-Type: application/xml');
$out=new SimpleXMLElement('<response/>');
...
die($out->asXML());
There are plenty of tuts online explaining how to use XML in AS3.
There are several ways to do this. I would suggest one of these two:
1: Add buttons to the sprite containing your TextField at the exact position of the text.
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.text.TextField;
public class Test extends MovieClip
{
private var textField : TextField;
private function onButtonClick (ev:Event) : void {
trace (ev.target.name);
}
public function Test ()
{
textField = new TextField();
textField.multiline = true;
textField.autoSize = "left",
textField.wordWrap = false;
addChild (textField);
var tx:String = "<p>Ramdom place 1 \n"+
"This interesting spot is near <link to=\"ramdo2\">ramdom place2</link>. And so, so so...</p>";
var xml : XML = new XML(tx);
textField.text = tx.replace (new RegExp (/(<[^(><.)]+>)/gm), "");
for each ( var link:XML in xml.link)
{
var linkText : String = link.text( );
var startIndex : int = textField.text.indexOf( linkText );
var endIndex : int = startIndex + linkText.length-1;
var startBox : Rectangle = textField.getCharBoundaries( startIndex );
var endBox : Rectangle = textField.getCharBoundaries( endIndex );
var button:Sprite = new Sprite();
button.graphics.beginFill(0,.1);
button.graphics.drawRect (startBox.x, startBox.y,(endBox.x - startBox.x)+endBox.width, (endBox.y-startBox.y)+endBox.height);
button.graphics.endFill();
button.name = link.#to;
button.addEventListener (MouseEvent.CLICK, onButtonClick);
button.buttonMode = true;
addChild (button);
}
}
}
}
( I realize this is very dirty, but you get the idea )
2: replace <link> with actual <a> links and use TextEvent.LINK to pass an argument:
package
{
import flash.display.MovieClip;
import flash.events.TextEvent;
import flash.text.TextField;
public class Test extends MovieClip
{
private var textField : TextField;
private function onTextEvent (ev:TextEvent) : void {
trace (ev.text);
}
public function Test ()
{
textField = new TextField();
textField.multiline = true;
textField.autoSize = "left",
textField.wordWrap = false;
addChild (textField);
var tx:String = "<p>Ramdom place 1 \n"+
"This interesting spot is near <link to=\"ramdo2\">ramdom place2</link>. And so, so so...</p>";
textField.htmlText = tx.replace ("<link", "<a").replace ("/link>", "/a>").replace ("to=\"", "href=\"event:");
textField.addEventListener (TextEvent.LINK, onTextEvent);
}
}
}