Flash builder, embed json compile error - json

I am using flash builder 4.7.
I tried to embed a json file while I got an error says:"../strings.json is of an unknown file
type which can't be embedded".
Here is my code.
[Embed(source="../media/data/strings.json"), mimeType="application/octet-stream"]
public static const JsonData:Class;
I have no idea how to fix it.
I am using AIR SDK 3.4
I want to use embedded method since it's always annoying to access local resource (the global flash setting).

I checked the syntax you posted for embedding json file is incorrect.
Please make it correct, it should be like
[Embed(source="a.json", mimeType="application/octet-stream")]
public var jsonData:Class;
Then you can access json data like this:-
var str:String = new String(new jsonData());
var obj:Object = JSON.parse(str);
Please make sure your a.json file must have a valid json data.

Related

JSON Path Extractor - missing DummySampler

I have a problem with jMeter and JSON Path Extractor.
I downloaded zip file for this plugin and copy content to ext file as it is written on the page. Then I also downloaded jmeter-plugins-manager-0.10.jar and copy it into ext folder.
Next step - downloaded a sample:
https://jmeter-plugins.org/img/examples/JSONPathExtractorExample.jmx
When i try to import it i'm getting exception:
missing
com.thoughtworks.xstream.mapper.conversionException:kg.apc.jmeter.samplers.DummySampler:kg.apc.jmeter.samplers.DummySampler
EDITED:
I love samples and documentation for libraries. There is no information about install additional jars... just download:
https://jmeter-plugins.org/?search=jpgc-dummy
And show must go on
Since JMeter 3.0 you don't need any plugin for JSON.
There is natively a new one :
http://jmeter.apache.org/usermanual/component_reference.html#JSON_Path_PostProcessor
Regarding the issue maybe you can report the problem to jmeter-plugins project
i used JSR223 Sampler where i parse input json and validate it's values in pure JavaScript. It seems more simple.
Here is and example code:
var json = JSON.parse(SampleResult.getResponseDataAsString());
//get your jmeter context
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();
if(json[0].itemId != 1){
AssertionResult.setFailureMessage(json);
AssertionResult.setFailure(true);
} else {
//and put data to this context, that you can use it in other components.
vars.put('validationJsonRequest', true);
}
To see added data just use Debug Sampler or Debug post processor (which you can investigate in View Result Tree)

Design time instantiation issues when accessing xml file using XDocument.Load

In my windows store app using the Visual Studio 2012 designer I want to be able to load some model objects for the designer. I've done this plenty of times before where I supply a xaml file using the ms-appx:/// uri without error. However, for this project I need to be able to instantiate a class and have it convert raw xml of a different format into my model objects.
I'm using the following xaml to instantiate my class for the designer:
d:DataContext="{Binding Source={d:DesignInstance Type=model:Walkthroughs, IsDesignTimeCreatable=True}}"
In my Walkthroughs class had code that did this initially:
public Walkthroughs()
{
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
AppDataLoader.LoadWalkthroughs(this, XDocument.Load("ms-appx:///SampleData/walkthroughs.xml"));
}
I first ran into an issue where the XDocument.Load did not understand the ms-appx:/// uri so I modified my code to something very simplistic:
AppDataLoader.LoadWalkthroughs(this, XDocument.Load(#"C:\walkthroughs.xml"));
Now I get access to path '' is denied.
I've tried several directories as well to no avail. I'm even running Visual Studio as an Administrator. If I remove the prefix altogether I get the following error:
Could not find file 'C:\Users\{me}\AppData\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache\omxyijbu.m4y\yofsmg1x.avh\walkthroughs.xml'.
Has anyone been able to load files from the file system when the designer instantiates objects?
Thanks,
-jeff
XDocument.Load(string uri) seems to have problems with loading Project resources from ms-appx:/
Regarding your second approach: Direct access to "C:" is not permitted. Ther is only a handful of special folders that you can access. Check out my workaround for this (my xml file is within the Assets folder of my project:
var storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
storageFolder = await storageFolder.GetFolderAsync("Assets");
var xmlFile = await storageFolder.GetFileAsync("data.xml");
var stream = await xmlFile.OpenReadAsync();
var rdr = new StreamReader(stream.AsStream(), System.Text.Encoding.GetEncoding("ISO-8859-1")); //needed if you have "ä,ß..." in your xml file
var doc = XDocument.Load(rdr);

Error: Access of undefined property JSON ... but it IS there

I am developing a Flash application (Flash Player 11 as target platform) that uses the AS3 Facebook API, which in turn uses as3corelib JSON functionality. Or at least it should do so.
However, in spite of including the latest version (.93) of the as3corelib.swc, I still get the "Error: Access of undefined property JSON". I also tried including the sources directly, to no avail.
Any ideas what I am doing wrong?
As I said, the *.swc is definitely included. As is the source code (all at the correct path).
Edit:
I have a more specific error message:
Error: Can not resolve a multiname reference unambiguously. JSON (from C:\Coding\FlashDevelop\Tools\flexsdk\frameworks\libs\air\airglobal.swc(JSON, Walker)) and com.adobe.serialization.json:JSON (from C:\flash_test\lib\as3corelib.swc)) are available.
I know that JSON is included in AIR, but I do not target AIR, so why does it try include the airglobal.swc?
Your problem is that Flash Player 11 and onwards has native JSON support, so the JSON class you are including is likely colliding with the one from as3corelib. Hence the ambiguity problem.
Try removing as3corelib entirely and see what happens.
Specify the full path to the class. Example, code:
...
var jsonData:Object = JSON.decode(loader.data);
...
will be
...
var jsonData:Object = com.adobe.serialization.json.JSON.decode(loader.data);
...

ActiveX in HTML

My requirement is to instantiate an object using new ActiveX() in html.
I have created a COM component SimpleActiveX using ATL. I have created the dll SimpleActiveX.dll for the same. In order to instantiate this component in html file I need to register the dll. So I registered the dll using the command regsvr32 %Path of dll%.
After doing so I am trying to create and instance of the component in html file as follows,
var req;
req = new ActiveX("SimpleActiveX.Hello"); //Assume Hello as a class.
req.Hi(); //Assume that Hi() is a member function of Hello.
By doing so I am unable to create the ActiveX object.
Html doesnt give any error too. I dont know whether I am doing anything wrong or am I missing anything.
Could anyone please tell me the proper steps to perform above operations.
How do I need to create the dll (Here in this case I have just build the ATL project in Visual Studio to generate the dll)?
What else do I need to do with the dll in case if I need to create an ActiveX object in html?
I had come across something called as <object> </object> tag in html where we mention the classid and attributes. I dont know whether I need to mention this in my html file or not.
Thanks for your help in advance.
To instantiate an ActiveX object in JavaScript, assuming the dll is correctly registered, you just have to use:
var req = new ActiveXObject("SimpleActiveX.Hello");
Unfortunately I don't know how to register a dll using Visual Studio.
Regarding the tag, it is used when you want to embed the object directly in your HTML code, so that it will be instantiated when the document loads, instead of using JavaScript.
For example:
<object id="myObject" classid="CLSID:2D360200-FFF5-11D1-8D03-00A0C959BC0A"></object>
Then you can access the COM object with
var myObject = document.getElementById("myObject").object

Packaging External File Dependencies in Flash

I just started learning ActionScript, so maybe this is obvious. I'm loading in .txt files to generate content for my Flash application. However, I can't seem to find a way to package the .txt files with the .swf when I publish my application. I'd like to be able to run the .swf from anywhere without it depending on the files. Is there a solution for this?
Thanks!
this is an excellent post by Emanuele Feronato:
how-to-embed-a-text-file-in-flash
Basically you use the embed syntax to embed the file as a ByteArray. The key method here is to call the toString() method on the ByteArray to convert to a string.
Hope this helps
Try loading .as files, with variables defined inside them. They're, technically, still text files and still easy to edit, but they get automatically encapsulated in the .swf.
In your main stage, you just add include 'included.as';. In your included.as file, you just define whatever variables you want, for example:
var someData:Array = new Array();
someData.push('This is some string');
someData.push('This is some other string');
After you include the as, you can call whatever variable you defined. And when you export, the .as file is embedded into the .swf.
Even better then just embedding a .txt with your flash, if you're more versed with programming I would suggest you to create a static class to store the values of your application.
Just like:
class StaticData {
static public var siteTitle:String = "My site name";
static public var homeMessage:String = "Lorem Ipsum dolor sit amet...";
static public var welcomeMessage:String = "Hello World";
static public var siteWidth:Number = 1024;
static public var siteHeight:Number = 780;
}
This is a safe and realiable way to store static values using a simple class structure, to use a value from the class, you just need to call inside your flash:
my_textfield.text = StaticData.siteTitle;
my_shape.width = StaticData.siteWidth;