How do i get a text object to change text dynamically? - createjs

I would like to receive an object by its given name. Right now i have to get the object and set text like that:
stage.children[0].instance.instance.cta2.text = "SAMPLE TEXT";
I've found this method:
stage.getChildByName("cta2");
But it just works on the right nesting level - like this:
stage.children[0].instance.instance.getChildByName("cta2");
I'm sure there's a simple solution right?

Related

How to set a required reasource location as a variable?

I'm currently making a game for an Advanced Higher computing course. After having my previous question answered perfectly and helping me a great bunch. I was wondering if you could share you wisdom upon me once again...
I've currently declared the variables, got the selection process narrowed down. All I'm sturggling to do is for it to recognise it's a variable and not the location itself.
UsedTile = My.Resources.Token(Turn)
CurrentTile = My.Resources.Colour(Turn)
I should also mention that UsedTile and CurrentTile are declared as Image so that it works with the rest of my progam.
Token is an array that swaps between 1 & 2 which is defined by Turn.
Sorry if i'm explaining this baddly, but basically I would want it to look something like
UsedTile = My.Resources.(Colour(Turn))
So that it is interchangable. All of the reasources are there, so for instance it would be a red tile it should show as
UsedTile = My.Resources.ColourRed.png
Thanks, I hope I've made it understandable. I'd happily upload more code if needed :)
-Lewis
It's a little unclear what it is that you are asking, but here are two suggestions that may help you. First, you may want to consider reading the resources once and storing them in some other data structure that makes them more convenient to access when you need them later. For instance, if you created a class like this:
Public Class ColourResources
Public Property TurnImages As Image(2)
End Class
Then you could create an array of them and fill them like this:
Dim colors(2) As ColourResources
colors(0).TurnImages(0) = My.Resources.ColourRed
colors(0).TurnImages(1) = My.Resources.ColourRedUsed
colors(1).TurnImages(0) = My.Resources.ColourBlack
colors(1).TurnImages(1) = My.Resources.ColourBlackUsed
Then when you need a particular image, you could just access in some way similar to this:
Dim tile As Image = colors(currentColor).TurnImages(currentTurn)
If your colors and turns are kept track of with some data type other than an Integer, you could use dictionaries instead of arrays.
My second suggestion is that it is possible to get the resource by string name rather than via resource-designer-auto-generated property. For instance, instead of this:
UsedTile = My.Resources.ColourRed
You could also access the same image like this:
UsedTile = DirectCast(My.Resources.ResourceManager.GetObject("ColourRed"), Image)
Depending on your needs, that may be useful to you.

How to use Get command in Monkey talk?

Does anybody know how to use the Get command in monkey talk?
In monkey talk guide only the command is written but no syntax is present.
Here is an example for you,
var x = app.label("label1").get("x","value")
Above line will get the value of label1 and store it in variable x. You can change the second parameter "value" to ".text" or ".size" depending on your needs
since the question is not marked Answered and For the future reference i am answering this.
‘GET’ ACTION RETRIEVES COMPONENT PROPERTY VALUES
Syntax:
ComponenType MonkeyId Get varName propName
Works like an assignment statement (varName= propName)
The default property is “value”
// Get label value currently displayed
Label lastname Get name
// Enter name into input field
Input query EnterText ${name}
// Get the first table item
Table countries Get country items1
// Enter into input field
Input * EnterText ${country}
you can refer this document here, thanqs
I will try to explain using example. Suppose there is a ListView(Table) and you want to scroll till its last item.
//Define a variable
Vars * Define row
//Store size of list in variable row using Get. Check use of "Get" here
Table * Get row size %thinktime=20000
//Now stored variable can be used as per need. here I am using for scrolling
Table * ScrollToRow ${row} %thinktime=2000
Hope it helps you !!

How to use _root and this[] in same line?

Here's a chunk of code that WORKS when it's on the main timeline:
var DysonTarget:String = "S"+(random(40)+1);
this[DysonTarget].MyType = "Dyson Sphere";
this[DysonTarget].gotoAndStop(this[DysonTarget].MyType);
It's choosing a number between 1 and 40, adding an S before it, and going into one of forty movie clips on the main stage with instance name S1, S2. . . S40 etc. Then it will display an image in the chosen clip. But to make this truly work the way I want to, I have to put the above code inside a movie clip. So I tried this, after declaring my variable on the main stage:
_root.this[DysonTarget].MyType = "Dyson Sphere";
_root.this[DysonTarget].gotoAndStop(this[DysonTarget].MyType);
It didn't compile, the error message said "Expected a field name after the '.' operator. Trying it with _parent returned the same message. With _level0 didn't work at all, and placing the _root and _parent inside the bracket didn't work either. I haven't been able to find any answer online because trying to type "this" into a search is too vague to return an answer about the actual command.
. . .help me :(
A friend of mine who is a software developer helped me on this one. Here's what we figured out:
First you declare variable DysonTarget on the main timeline:
var DysonTarget:String = "S" + (random(40)+1);
Then inside the movie clip, use this:
_level0[DysonTarget].MyType = "Dyson Sphere';
_level0[_level0.DysonTarget].gotoAndStop(_level0[_level0.DysonTarget].MyType);
I've tried this a few other ways, and the above method is the only one that works the way it's supposed to. But it works! My impression is the brackets tell it to look for an object named what the variable is set to, rather than an object with the same name as the variable.

Apache POI: Partial Cell fonts

If I crack open MS Excel (I assume), or LibreOffice Calc (tested), I can type stuff into a cell, and change the font of parts of the text in a cell, such as doing, in one cell, :
This text is bold and this text is italicized
Again, let me reiterate, that this string could exist in the shown format in one cell.
Can this level of customization be achieved with Apache POI? Searching only seems to show how to apply a font to an entire cell.
Thanks
===UPDATE===
As suggested below, I ended up going with the HSSFRichTextString (as I'm working with HSSF). However, after applying fonts (I tried bold and underline), my text would remain unchanged. This is what I attempted. To put things in context, I am working on something sports-related, in which it is common to display a match up in the form "awayteam"#"hometeam", and depending on certain external conditions, I would like to make one or the other bold. My code looks something like this:
String away = "foo";
String home = "bar";
String bolden = "foo"
HSSFRichTextString val = new HSSFRichTextString(away+"#"+home);
if(bolden.equals(home)) {
val.applyFont(val.getString().indexOf("#") + 1, val.length(), Font.U_SINGLE);
} else if(bolden.equals(away)) {
val.applyFont(0, val.getString().indexOf("#"), Font.U_SINGLE);
}
gameHeaderRow.createCell(g + 1).setCellValue(val);
As you can see, this is a snippet of code from a more complicated function than is displayed, but the brunt of this is actual code. As you can see, I'm doing val.applyFont to part of a string, and then setting a cell value with the string. So I'm not entirely sure what I did wrong there. Any advice is appreciated.
Thanks
KFJ
POI does support it, the class you're looking for is RichTextString. If your cell is a text one, you can get a RichTextString for it, then apply fonts to different parts of it to make different parts of the text look different.
You would be drained if working with SXSSFWorkbook, as it does not support such formatting.
Check it here.
http://apache-poi.1045710.n5.nabble.com/RichTextString-isn-t-working-for-SXSSFWorkbook-td5711695.html
val.applyFont(0, val.getString().indexOf("#"), Font.U_SINGLE);
You should not pass Font.U_SINGLE to applyFont,but new a Font, such as new HSSFFont(), then setUnderline(Font.U_SINGLE).
example:
HSSFFont f1 = new HSSFFont();
f1.setUnderline(Font.U_SINGLE);
val.applyFont(0, val.getString().indexOf("#"), f1);

rails find by path

Maybe I'm not searching on the right keywords but: Is it possible to search given an object path?
I have '/businesses/2' and I'd simply like to do something like #object = Business.find('/businesses/2') to fetch that object
One way is to:
ids = params[:who_id].split('/')
#object = ids[1].singularize.constantize.find(ids[2])
But I'm wondering if there is a built in way since this seemed to me as something quite normal to do.
If you know that the id will be the last in the string then you can split the string by "/" and take the last element. If you're unsure, you may use regexp.
If you want also to perform a search depending on what's in your string (you do not know class name)) then use regexp to match a model name and then use these helpers:
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
to get a name of the class.
Like:
klass = _yor_extracted_string.singularize.constantize
object = klass.find(_id_here_)