0

I want my application to be able to read settings saved somewhere online (like in this case, deviantart sta.sh - http://sta.sh/024wsd5s7k0z). Obviously I get to work with is source code and the problem is to find substring contained between [startSettingsBlock] and [endSettingsBlock]. (<br /> is there to ensure I take the right piece of text.)

The part I'm interested in, line 207:

[number]=42<br />[character]=k<br />[amount]=6<br />[gay]=false<br />[ponies]=cool<br />[whazz]=idiot<br />[thisapp]=is gonna be awesome<br />[rainbow dash]=best pony<br />[lol]=sucks<br />[alice]=hasacat<br />[preferences]=3;6;8<br />[variable]=alice has a cat<br />[slowly]=getting there<br />[poop]=face

My code so far:

//bunch of imports here

valueButton.addEventListener(MouseEvent.CLICK, requestValue);

var pageLoader:URLLoader = new URLLoader();
var pageRequest:URLRequest = new URLRequest();
    pageRequest.url = "http://sta.sh/024wsd5s7k0z";
    pageRequest.method = URLRequestMethod.GET;
var pageContext:LoaderContext = new LoaderContext();
    pageContext.checkPolicyFile = true;
    pageLoader.addEventListener(Event.COMPLETE, readParams);
    pageLoader.load(pageRequest);
var opening:String = "[startSettingsBlock]<br />";
var closing:String = "<br />[endSettingsBlock]";
var rawSettings:String;

function requestValue(e:Event){
    var toFind:String = "["+inputTextField.text+"]=";
    var variableStartIndex:int = rawSettings.indexOf(toFind)+toFind.length;
    var variableEndIndex:int = variableStartIndex;
    //once I have raw settings (in any form), I do magics.
    valueTextField.text = rawSettings.substring(variableStartIndex, variableEndIndex);  
}

function readParams(e:Event){
     rawSettings = pageLoader.data.substring(
                        pageLoader.data.indexOf(opening)+opening.length, 
                        pageLoader.data.indexOf(closing));
}

After I run readParams, rawSettings equals

<!DOCTYPE html> <!--[if I

which is the beginning of the source code.

Whazz
  • 367
  • 2
  • 12

1 Answers1

0

I haven't tried your code but it looks like it's working fine to me, what is the problem ?

Anyway my suggestion is to use something different to store your settings online, a webserver allows you to save your data without all the html of the page or in the worst case that you don't have access to a server you can use a GitHub gist https://gist.github.com/ because you can access a gist, for example this:

https://gist.github.com/fhferreira/cc8fcefce8421dd2d6c4

in raw format:

https://gist.githubusercontent.com/fhferreira/cc8fcefce8421dd2d6c4/raw/85bcfa8f5ccc2dd074ff37536db540d5e993ae57/array-sum.js

You have a raw button in your gist. This is way simpler to analyze.

One last suggestion is to use a standard format (JSON is the most popular i think) to you can use an existing library to parse it. In case of json all the required code is already present in the standard library http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/JSON.html

wezzy
  • 5,897
  • 3
  • 31
  • 42
  • I have couple questions: Is GitHub without expiration date? Is it editable? I'll try and study JSON though, looks more practical. – Whazz Jun 10 '15 at 21:57
  • I don't think that they have an expiration date and of course you can edit a gist when you want. Have a look at JSON is very very simple and clear to read for a human and extremely popular – wezzy Jun 10 '15 at 22:27
  • For now it should be fine, as it is going to be for my personal usage, but later on, if people will want to use it, I'll have to find solution anyway. :) Customer > easy code. Thanks for help (and yeah, for my taste, it should work just fine as it is too) – Whazz Jun 10 '15 at 22:31
  • There's a lot of services that offers backend support for apps, they are primarily intended for mobile apps but I think that you can use them with your AS3 app. Try looking at https://parse.com/ or you just have to write a backend by yourself with login and a form. Another solution could be google docs – wezzy Jun 10 '15 at 22:34
  • There is the problem though, gist links, change after you edit them and I want to save the link directly in the app, not update it every time I change something. – Whazz Jun 11 '15 at 12:24