Convert text string to hexadecimal using flash builder - actionscript-3

I want to convert MAC Address into hexadecimal string using flash builder..
I used this code
var networkInterface : Object = NetworkInfo.networkInfo.findInterfaces();
var networkInfo : Object = networkInterface[0];
var physicalAddress : String = networkInfo.hardwareAddress.toString();
txtreq.text = physicalAddress + "-" + txtserial.text
var reqcode:uint = uint(txtreq.text);
var reqcode1:String = reqcode.toString(16);
txtact.text = reqcode1;
When I run the application,
txtserial.text = 123 and physicalAddress = C6-17-31-A9-EF-FF...
but txtact.text got 0.
Then how I fix the problem and In flex Builder how I convert FF-FF-FF-FF-FF like text into hexadecimal code...

You should use parseInt(reqcode,16) instead of reqcode.toString(16);

Related

Javascript Base64 Decoding to Invalid JSON Output

I'm using a Firebase Cloud function to receive a JSON payload in an http request from the App Store (server-to-server notifications) that contains a Base64 encoded string. I'm decoding using:
const latestReceipt = request.body.latest_receipt ? Buffer.from(request.body.latest_receipt, 'base64').toString() : null;
This is works fine in another function to decode a message coming from the Google Play Store. The decoded string coming from Apple, however, is an invalid JSON object.
{
"original-purchase-date-pst" = "2019-09-20 16:40:20 America/Los_Angeles";
"quantity" = "1";
"subscription-group-identifier" = "****";
"unique-vendor-identifier" = "****";
"original-purchase-date-ms" = "1569022820000";
"expires-date-formatted" = "2019-09-24 02:55:47 Etc/GMT";
"is-in-intro-offer-period" = "false";
"purchase-date-ms" = "1569293447000";
"expires-date-formatted-pst" = "2019-09-23 19:55:47 America/Los_Angeles";
"is-trial-period" = "false";
"item-id" = "1478806339";
"unique-identifier" = "******";
"original-transaction-id" = "1000000570864027";
"expires-date" = "1569293747000";
"transaction-id" = "1000000571530192";
"bvrs" = "11";
"web-order-line-item-id" = "1000000047099385";
"version-external-identifier" = "0";
"bid" = "****";
"product-id" = "storage_increase";
"purchase-date" = "2019-09-24 02:50:47 Etc/GMT";
"purchase-date-pst" = "2019-09-23 19:50:47 America/Los_Angeles";
"original-purchase-date" = "2019-09-20 23:40:20 Etc/GMT";
}
I'm assuming that I'm doing something wrong, but I'm not sure what exactly. I wouldn't expect the App Store to send invalid JSON.

Implicit coercion of a value of type String to an unrelated type uint

AS3 FLASH
Can someone help me, why I can't "convert a string to a color"
var loadFeetColor2:String = 5435435
feet_cpicker2.selectedColor = loadFeetColor2;
loadColorInfo8_2.color = feet_cpicker2.selectedColor;
guy.guyanimation.foot2.colorMC2.transform.colorTransform = loadColorInfo8_2;
It's not work. But It's work:
feet_cpicker2.selectedColor = 5435435
loadColorInfo8_2.color = feet_cpicker2.selectedColor;
guy.guyanimation.foot2.colorMC2.transform.colorTransform = loadColorInfo8_2;
? why
If you want to set something as a String literal you have to put it in speech marks, ie:
var loadFeetColor2:String = "5435435";
If, instead, you need that variable to be an int you should declare it as such:
var loadFeeColor2:int = 5435435;
selectedColor method params would take unsigned integer only. You shouldn't pass a string. so try this.
var loadFeetColor2:String = 5435435
feet_cpicker2.selectedColor = uint(loadFeetColor2);
loadColorInfo8_2.color = feet_cpicker2.selectedColor;
guy.guyanimation.foot2.colorMC2.transform.colorTransform = loadColorInfo8_2;

Replace text surrounded by *** with <b> and </b>

Let's say I have a string
var myString: String = "This ***is*** my ***string***"
Now I'm searching for a way to replace the stars with html-bold tags.
After replacement the code should look like:
"This <b>is</b> my <b>string</b>
What I've done so far:
var boldPattern : RegExp = /\*\*\*.*?\*\*\*/;
while(boldPattern.test(goalOv[gCnt][1])){
myString = myString.replace(boldPattern, "<b>"+myString+"</b>");
}
This ends up with an endless Loop (because I'm assigning the string to itself).
Thanks
I'm not good at regular expressions, but I think this simple solution will do the trick:
var boldPattern : RegExp = /(\*\*\*)/;
var myString: String = "This ***is*** my ***string***";
var count:int = 0;
while(boldPattern.test(myString))
{
if(count % 2 == 1)
myString = myString.replace(boldPattern, "</b>");
else
myString = myString.replace(boldPattern, "<b>");
count++;
}
As Gio said, that looping isn't the best way of replacing globally. You should instead do the following to avoid looping and have replacement in one pass over the string.
var boldPattern :String = "This ***is*** my ***string***";
var myString:RegExp = /\*\*\*([^*]*)\*\*\*/g;
var replText:String = "<b>$1</b>";
myString = myString.replace(boldPattern, replText);
Also, if you want to do it more correctly to allow for myString have have string of 1 or 2 *, you can use:
/\*\*\*(([^*]+\*{0,2})+)\*\*\*/g

Reverse engineering - Flash app

I have that code:
private function handleFlashVarsXmlLoaded(event:Event) : void
{
var secondsplit:String = null;
var item:Array = null;
var string:* = XML(String(event.target.data));
var notsplited:* = string.vars_CDATA; //what is .vars_CDATA?
var splitted:* = notsplitted.split("&");
var datacontainer:Object = {};
var index:Number = 0;
item = secondsplit.split("=");
datacontainer[item[0]] = item[1];
this.parseFlashVars(datacontainer); // go next
return;
}
That function is loaded when URLLoader is loaded.
I think that this function parse a XML file to string(fe. param1=arg1&param2=arg2), then split it by "&" and then by "=" and add data to datacontainer by
datacontainer["param1"] = "arg1"
But how should the XML file look like and what is string.vars_CDATA
I think, vars_CDATA is just a name of XML field, becourse variable named "string" is contains whole XML. So var "notsplited" contains a String-typed data of this field (I think so, becourse of the line "var splitted:* = notsplitted.split("&");", which splits String to Array).

Parsing a string, using action script

I am working on a flex site,
I want to parse the string below:
http://virtual.s1.c7beta.com/rpc/raw?c=Pictures&m=download_picture&key=a4fb33241662c35fe0b46c7e40a5b416&session_id=2b7075f175f599b9390dd06f7b724ee7
and remove the &session_id=2b7075f175f599b9390dd06f7b724ee7 from it.
How should i do it.
also later on when i get the url from database without session_id, i will attach the new session_id to it. Please tell me how to do that too.
Regards
Zeeshan
Not the short version but you can use URLVariable to get all the field(name, value) into an object and then add or delete any field you want.
Separate url and query:
var url : String = "http://virtual.s1.c7beta.com/rpc/raw?c=Pictures&m=download%5Fpicture&key=a4fb33241662c35fe0b46c7e40a5b416&session%5Fid=2b7075f175f599b9390dd06f7b724ee7";
var idxQMark : int = url.indexOf("?");
var qry : String = "";
Build url variable from query
var uv : URLVariables = new URLVariables();
if (idxQMark > 0) {
qry = url.substr(idxQMark + 1);
url = url.substr(0, idxQMark);
uv.decode(qry);
}
NOw you can access whatever field you need or delete them
delete uv.session_id;
Rebuild the query when needed
qry = uv.toString();
// get back you new URL
if (qry != "") {
url = url + "?" + qry;
}
For URI parsing check out the URI class provided in as3corelib.
http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/net/URI.as
For your specific case, you can clear the parts of the URI you don't want.
var url : String = "http://virtual.s1.c7beta.com/rpc/raw?c=Pictures&m=download%5Fpicture&key=a4fb33241662c35fe0b46c7e40a5b416&session%5Fid=2b7075f175f599b9390dd06f7b724ee7";
var uri : URI = new URI(url);
uri.query = "";
uri.fragment = "";
var shortenedUrl : String = uri.toString();
Or if you know you want to construct your url from just the scheme, authority, and path (i.e., you don't need to preserve port, username, password, etc.) you can build the url from parts.
var shortenedUrl : String = uri.scheme + "://" + uri.authority + "/" + uri.path;
If you're not sure that sessionid will be last you could split on the & using the as3 string.split functionhttp://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#split%28%29
then rebuild the string using a for loop leaving out strings that start with session_id using the string.indexOf function http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#indexOf%28%29 to see if "session_id" is at index 0
You can use regular expressions in Flex ... here's an example.
Assuming the session ID will always be the last variable in the query string:
var newStr:String = myStr.slice(0, myStr.indexOf("&session"));