Wildcard for hitTestObject ActionScript3 show Instance Name - string

I have movieClips namely rec1, rec2, rec3, rec4...
Then, I would addChild another movieclip(circle_mc) to those rec MovieClips.
I want to use the hitTestObject... Something like this:
circle_mc.hitTestObject(this["rec" + numStringTarget])
If I specify number on the numStringTarget variable, I can only attach to one of the "rec" movieclips. What I want is the capability of circle_mc to be added on any "rec" movieclips. Is there any way to use wildcard? Or any way to solve it?
I want the code to become like this:
circle_mc.hitTestObject(contains String "rec") then addChild..
I hope someone can solve it or just give me some helpful links to read about. Thanks in advance.
I do not want to set all these statements this way:
circle_mc.hitTestObject(rec1);
circle_mc.hitTestObject(rec2);
circle_mc.hitTestObject(rec3);
circle_mc.hitTestObject(rec4);
what if I have a hundreds or thousands... I want to test if the movieclip, as long as it has word "rec" on its instance name, it will be tested.
Or it could be in another situation. My circle_mc is draggable. Then when it hit another movieclip on stage, is there any way to show up the instance name hit by the circle_mc?

for (var i:int = 0; i < _totalRecObjects; ++i) {
circle_mc.hitTestObject(this["rec" + i]);
}

Related

document.createTextNode not working :/

So i am making this program where i need to create an ordered list with lots of list elements inside. This is the code:
for(i = 0; i < numbers.length; i++) {
document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(document.createElement("ls"));
}
It only creates the list elements, it doesn't put the text nodes anywhere in the html document. :/
Does anyone know why this happens and how to fix it? Would really help me out.
Instead of adding the "ls" element you've created on the first row to the "list" element, you're creating a new (empty) one and adding it.
Change it to:
var ls = document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(ls);

How to Remove the addPreSearch Filter

I am trying to remove the PreSearch filer and my code is as below. How can I achieve the same?
Xrm.Page.getControl("productid").removePreSearch(function () {
Object
});
Xrm.Page.getControl("productid").addPreSearch(function () {
fetchxml2();
});
function fetchxml2() {
var fetchXml1 = "<filter type='and'>"
fetchXml1 += "<condition attribute='productid' operator='in' >";
for (var i = 0; i < Itemid.length; i++) {
fetchXml1 += "<value>" + Itemid[i] + "</value>";
}
fetchXml1 += "</condition>";
fetchXml1 += "</filter>";
Xrm.Page.getControl("productid").addCustomFilter(fetchXml1);
//Xrm.Page.getControl("productid").removePreSearch(fetchXml1);
};
In order to be able to remove the handler via removePreSearch, avoid using an anonymous function by creating a named function and using that in both addPreSearch and removePreSearch:
function preSearchHandler(){
fetchxml2();
}
Xrm.Page.getControl("productid").removePreSearch(preSearchHandler);
Xrm.Page.getControl("productid").addPreSearch(preSearchHandler);
Just wanted to add this to the discussion:
If you, say, have three different custom filters on a lookup field, the functionality will stack when you apply a new filter.
For example, if you have an option set that calls addPreSearch() on the field, if you select all three different options, you will have all three filters applied to the field simultaneously.
say the option set has three options of [option A, option B, option C],
the corresponding functions are, for simplicity [filterA, filterB, filterC],
on the change event of the option set, for each filter that you apply, simply remove the other two (in this case).
if (optionSet == 810500000) {//option A
Xrm.Page.getControl('lookup').addPreSearch(filterA);
Xrm.Page.getControl('lookup').removePreSearch(filterB);
Xrm.Page.getControl('lookup').removePreSearch(filterC);
}
else if (optionSet == 810500001) {//option B
Xrm.Page.getControl('lookup').addPreSearch(filterB);
Xrm.Page.getControl('lookup').removePreSearch(filterA);
Xrm.Page.getControl('lookup').removePreSearch(filterC);
}//so on and so forth
I hope this helps someone out, I was able to apply custom filters to a lookup based on four distinct selections and remove the "stackable" filters by addition and removal in this manner. It's a little ugly, but, hey, it works. At the end of the day, sometimes the most elegant solution is to just win, win win win win.
If you need more context (fetchXml) and such, I can post that, too...but it doesn't really go along with the point I was trying to make. These filters can be applied simultaneously! That's the main idea I wanted to convey here.

Referrring to movie clips using variable strings

I want to know how to use a variable string to reference a movie clip in a hierarchy in AS2.
For example, and please forgive my newbie coding:
If my variable is defined as:
_root.MovieName = "Bob";
Then I'd like to be able to write:
_root.MovieName.ChildClip.gotoAndPlay("Label");
Where MovieName is the string "Bob" and not an actual instance called "MovieName". So Flash looks for an instance of "Bob" and goes into the child clips from there.
Is there any way to do this?
_root actually is a reference to the "root" of the movie, which also inherits a bunch of properties, it behaves like an object, so yes, you can do things like the following:
trace(_root["Bob"]); //Should return the instance.
var movieName = "Bob";
trace(_root[movieName]); //Should be the same.
I FOUND THE ANSWER!
In order to refer to movie clip instances using variables, first declare that variable as a string, then use the this[] handler. Here is the code that worked for me and the page that held it:
// CREATE THE STRING
var newString:String = "movieClipInstanceName";
// ASSUMING YOU ALREADY HAVE A MOVIECLIP WITH AN INSTANCE NAME OF "movieClipInstanceName" ON STAGE,
//CHANGE THE ALPHA OF THE MOVIECLIP TO 0
this[newString].alpha = 0;
And the page:
http://www.kirupa.com/forum/showthread.php?327501-Converting-String-to-Movie-Clip-Instance-Name
Big thanks to everyone who pitched in to help me!

Is there a way to change the text of checked/unchecked MCheckBox states?

How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?
Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.
Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171
Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.

How to get number of options in Combo Box in SSJS?

I've tried getComponent("ComboBoxID").getChildCount() but that appears to not return the correct number. Anyone know if there is a method I can use? Or maybe a function needs to be created?
EDIT - And is there a way to loop through the options and get the values like in CSJS?:
for (var i = 1; i < comboBox.options.length; i++){
pmtPlan = comboBox.options[i].value;
...
Maybe this XSnippet can help:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=get-selectable-values-of-a-component
Instead of printing the selectable value(s) you have to count them.
Hope this helps
Sven

Resources