Is there a reason a function won't accept a number higher than 4 in AS3? - actionscript-3

you know any reason why a function won't accept any number higher than 4?
This is all I'm doing. Works for 0-4, but once I hit 5 or higher, I get "A term is undefined and has no properties." But if I just put the number 5 in there, it all works just fine, so it's not an issue with the xml.. for some reason the function just won't accept anything higher than 4. weirding me out..... I can't see an explanation for it.
loadEpSynopsis(5);
function loadCharSynopsis(charNumber:Number):void
{
synopsisBox.titleText.text = bXml.characterlist.character[charNumber].charactername;
synopsisBox.descriptionText.text = bXml.characterlist.character[charNumber].characterdesc;
}

The value of "bXml.characterlist" is probably only 5 characters long, so indexing higher than that is returning "null", which has no "charactername" property.

Related

Firefox submits number fields as decimals

Firefox seems to submit input fields of type number as decimals independant of its visible value (e.g.: visible value: 1, real value/posted data: 1.0).
My backend cannot handle it as it expects an integer.
But I still want to use the number type as it handles the keyboard layout on mobile devices.
I already tried to set the step attribute to 1 (which is default anyway).
Sorry, but you are stuck with this way of formatting number fields if you want to keep using that type of control.
What you can do is create a hidden input that is updated when the number input field changes. You can format the value you put in there the way you like to.
So in short, the best thing is to get your backend straight, but that might be out of your hands. Else you can use the workaround provided.
Well actually it’s not a bug; the form field is behaving as defined by the W3C.
Numeric input fields can take additional attributes “min” and “step”, which constrain the range of values allowed in your input.
This is because the default step is 1. So far, so obvious.
However, the step attribute also determines which values are valid, so a step of 1 means you can enter 1, 2, 3 etc. and a step of 2 means you can enter 2, 4, 6 etc, and when you click the up/down buttons the number will increase/decrease by 2 each time, but entering 3 or 5 in the box will cause a validation error. You can also use a decimal value: for example, a step of 0.3 will allow values such as 0.3, 0.6, 0.9 etc, but not 1 or 2.
I was completely wrong. I filled the input from my backend and it was a double value. When using the type integer it only submits "1".

How edge indexing works in graphhopper?

I'm here with a new question.
I'm making a custom algorithm that need precomputed data for the graph edges. I use the AllEdgesIterator like this :
AllEdgesIterator it = graph.getAllEdges();
int nbEdges = it.getCount();
int count = 0;
int[] myData = new int[nbEdges];
while (it.next())
{
count++;
...
}
The first weird thing is that nbEdges is equal to 15565 edges but count is only equal to 14417. How is it possible ?
The second weird thing is when I run my custom A* : I simply browse nodes using the outEdgeExplorer but I get an IndexOutOfBound at index 15569 on myData array. I thought that the edge indexes were included in [0 ; N-1] where N is the number of edges, is it really the case ?
What could be happening here ? By the way, I have disabled graph contraction hierarchies.
Thank you for answering so fast every time !
The first weird thing is that nbEdges is equal to 15565 edges
but count is only equal to 14417. How is it possible ?
This is because of the 'compaction' where unreachable subnetworks are removed, but currently only nodes are removed from the graph the edges are just disconnected and stay in the edges-'array' marked as deleted. So iter.getCount is just an upper limit but the AllEdgeIterator excludes such unused edges correctly when iterating and has the correct count. But using iter.getCount to allocate your custom data array is the correct thing to do.
Regarding the second question: that is probably because the QueryGraph introduces new virtual edges with a bigger edgeId as iter.getCount. Depending on the exact scenario there are different solutions like just excluding or using the original edge instead etc

Simulink Matlab function block deleting rows from a vector

That i want to do is to delete certain rows (or columns doesn't really mater...) from a given vector.
By going through Simulink's components found out that there is nothing performing such an operation,there are blocks help one add elements but nothing clearly for removing,so ended up trying to delete them by using a function block and following the online examples that demonstrate the usage of "[]".Lets say that i want to delete the second column of the vector u,i do u(:, 2) = [];.
That works absolutely fine in a separate m file or function but unfortunately not in a function block returning:
"Simulink does not have enough information to determine output sizes for
this block. If you think the errors below are inaccurate, try specifying
types for the block inputs and/or sizes for the block outputs."
and:
Size mismatch (size [4 x 4] ~= size [4 x 3]).
The size to the left is the size of the left-hand side of the assignment.
Function 'MATLAB Function' (#107.41.42), line 4, column 1:
"u"
Launch diagnostic report.
Is there any alternative you can suggest to remove several elements in a given vector in Simulink?
Thanks in advance
George
Finally,managed to do it without function block.There is a much easier way,by using Pad,and defining the output vector to be shorter than the input resulting in truncation.

more minimaler cubism.js horizon chart from json example

Following up on a previous question... I've got my minimal horizon chart example much more minimaler than before ( minimal cubism.js horizon chart example (TypeError: callback is not a function) )
<body>
<div class="mag"></div>
<script type="text/javascript">
var myContext = cubism.context();
var myMetr = myContext.metric(function(start, stop, step, callback) {
d3.json("../json/600s.json.php?t0=" + start/1000 + "&t1=" + stop/1000 + "&ss=" + step/1000, function(er, dt) {
if (!dt) return callback(new Error("unable to load data, or has NaNs"));
callback(null, dt.val);
});
});
var myHoriz = myContext.horizon()
.metric(myMetr);
d3.select(".mag")
.call(myHoriz);
</script>
</body>
The d3.json() bit calls a server side .php that I've written that returns a .json version of my measurements. The .php takes the start, stop, step (which cubism's context.metric() uses) as the t0, t1, and ss items in its http query string and sends back a .json file. The divides by 1000 are because I made my .php expect parameters in s, not ms. And the dt.val is because the actual array of my measurements is in the "val" member of the json output, e.g.
{
"other":"unused members...",
"n":5,
"val":[
22292.078125,
22292.03515625,
22292.005859375,
22292.02734375,
22292.021484375
]
}
The problem is, now that I've got it pared down to (I think) the bare minimum, AND I actually understand all of it instead of just pasting from other examples and hoping for the best (in which scenario, most things I try to change just break things instead of improving them), I need to start adding parameters and functions back to make it visually more useful.
Two problems first of all are, this measurement hovers all day around 22,300, and only varies +/- 10 maybe all day, so the graph is just a solid green rectangle, AND the label just says constantly "22k".
I've fixed the label with .format(d3.format(".3f")) (versus the default .2s which uses SI metric prefixes, thus the "22k" above).
What I can't figure out is how to use either axis, scale, extent, or what, so that this only shows a range of numbers that are relevant to the viewer. I don't actually care about the positive-green and negative-blue and darkening colours aspects of the horizon chart. I just used it as proof-of-concept to get the constantly-shifting window of measurements from my .json data source, but the part I really need to keep is the serverDelay, step, size, and such features of cubism.js that intelligently grab the initial window of data, and incrementally grab more via the .json requests.
So how do I keep the cubism bits I need, but usefully change my all-22300s graph to show the important +/- 10 units?
update re Scott Cameron's suggestion of horizon.extent([22315, 22320])... yes I had tried that and it had zero effect. Other things I've changed so far from "minimal" above...
var myHoriz = myContext.horizon()
.metric(myMetr)
.format(d3.format(".2f"))
.height(100)
.title("base1 (m): ")
.colors(["#08519c", "#006d2c"])
// .extent([22315, 22320]) // no effect with or without this line
;
I was able to improve the graph by using metric.subtract inserting it above the myHoriz line like so: (but it made the numerical label useless now):
var myMetr2 = myMetr.subtract(22315);
var myHoriz = myContext.horizon()
.metric(myMetr2)
.format...(continue as above)
All the examples seem so concise and expressive and work fine verbatim but so many of the tweaks I try to make to them seem to backfire, I'm not sure why that is. And similarly when I refer to the API wiki... maybe 4 out of 5 things I use from the API work immediately, but then I always seem to hit one that seems to have no effect, or breaks the chart completely. I'm not sure I've wrapped my head around how so many of the parameters being passed around are actually functions, for one thing.
Next hurdles after this scale/extent question, will be getting the horizontal time axis back (after having chopped it out to make things more minimal and easier to understand), and switching this from an area-looking graph to more of a line graph.
Anyway, all direction and suggestion appreciated.
Here's the one with the better vertical scale, but now the numerical label isn't what I want:
Have you tried horizon.extent? It lets you specify the [min, max] value for the horizon chart. By default, a linear scale will be created to map values within the extent to the pixels within the chart's height (specified with `horizon.height or default to 30 pixels).

Actionscript 3: Referencing data in groupings of movieclips

I'm a very new programmer. I'm making a character calculator for a friend of mine's game, but mostly for practice for myself.
I'm programming in Actionscript and have been trying to reference Data in Lists, which has been working fine, except when my lists are grouped together with anything else as one symbol(MovieClip).
I have looked around the internet and tried getChild() (though I am not positive symbols in other symbols mean they are children of them), as well as putting MovieClip(parent).ListName.Data to try and reference it. I have also simply tried putting ListParent.ListName.Data to reference it, but I'm afraid I'm at a loss.
I'm sure the answer is very obvious but Google, as it seemed, did not pinpoint my issue. Here is the code -- my list's dataProvider is pretty much just 1, 2, 3, 4, 5 for my data points, so here I'm trying to reference list selection 2:
earthponyRacials.earthponyList1.addEventListener(Event.CHANGE, testText);
function testText(event:Event) {
if(earthponyRacials.earthponyList1.data == 2){
trace("Function working?");
}
}
This is my reference error:
ReferenceError: Error #1069: Property data not found on fl.controls.List and there is no default value.
at CharacterCalculator_fla::MainTimeline/testText()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::SelectableList/handleCellRendererClick()
I'm sorry if this is a really obvious question.
You have to access the lists data using:
YourList.dataProvider.getItemAt( ItemsIndex ).data;
You can also get its label by replacing .data with .label
The items index is the same as accessing an array so item 2 is index 1 item 1 is index 0
Hope this helps!