I am having problems accessing sub-children of my displayObject. Here is my code:private
function resizeTag(event:MouseEvent):void{
var currTagPos:Number = 1;
var theTagBox:DisplayObject = tagCanvas.getChildAt(currTagPos); //i have confirmed that it exists on the stage and has sub-children
trace(theTagBox.getChildAt(0).width);
}
Essentially I'm trying to get:
tagCanvas.getChildAt(currTagPos).getChildAt(0).width;
but it's not working. Thanks for any guidance you can provide :)
Looks like I needed to call it as a DisplayObjectContainer. I did this instead:
trace((tagCanvas.getChildByName(currTagName) as Canvas).getChildAt(3) as Button);
I found this post which helped me figure it out:
http://www.nabble.com/undefined-method-getChildAt-td19812715.html
Related
If some function or library does not have DefinitelyTyped, I know these two ways to stop warnings.
interface Navigator {
getUserMedia: any
}
declare let RTCIceCandidate: any;
But right now, this 3rd-part library Collection2 is used like this:
let ProductSchema = {};
let Products = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);
It give me a warning:
Property 'attachSchema' does not exist on type 'Collection'.
I tried the way below, but it does not work.
interface Collection {
attachSchema: any
}
How can I stop this warning? Thanks
EDIT:
Eric's adding any way solves the problem.
let Products:any = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);
But now a new trouble comes:
let UserSchema = {};
Meteor.users.attachSchema(UserSchema);
Since Meteor.users is built in, so there is no place to add any. How to solve this? Thanks
Thanks for Amid's help. So the way is:
(<any>Meteor.users).attachSchema(UserSchema);
I feel like I must be doing this wrong. I've got a function that is supposed to construct a query based on an API's description of available fields. Here's what I've got:
var query_fields = getQueryFieldsFor(sobject_name);
// Need query fields for the next statement, which actually does the query
public function getQueryFieldsFor(sObject:String):String{
//helper function to get queryfields for given sobject
var queryFields:String = '';
app.connection.describeSObject(sObject,
new mx.rpc.Responder(
function(result:DescribeSObjectResult):void{
var returnFields:String = '';
for ( var field:Field in result.fields ){
if(field.active){
returnFields.concat(field.name+',')
}
}
returnFields.slice(0, returnFields.length-1); //remove last comma
queryFields = returnFields;
}, function(error):void{
Alert.show('error in getQueryFieldsFor function');
})
);
return queryFields;
}
I know this doesn't work, and I think I understand why. However, I keep running into this type of issue and I believe I'm just thinking about it/designing it wrong. So what's a better pattern here? Would really appreciate any insight on this. Many thanks in advance.
It would be better to externalize your functions and execute your next line of code after the fact:
public function getQueryFieldsFor(sObject:String):String
{
var responder:Responder = new Responder( onResult, onFault);
app.connection.describeSObject(sObject, responder);
}
private function onResult(result:DescribeSObjectResult):void
{
var returnFields:String = '';
for ( var field:Field in result.fields ){
if(field.active){
returnFields.concat(field.name+',')
}
}
returnFields.slice(0, returnFields.length-1); //remove last comma
queryFields = returnFields;
}
Your main problem though is not the code, but a lack of thinking asynchronously. You cannot have a function called "getQueryFields" that will return it instantly. What you want to do is think in the request/response way. You're trying to get some data, a request is made to a service, gets the data back, updates a property which is then binded to a view which gets redrawn. This is the proper way to do any webapp.
It might be beneficial for you to also look at application frameworks like RobotLegs and Parsley since it helps you manage these situations. Parsley also has a task library which lets you perform several asynchronous task one after another.
i am trying to figure out if i can in anny way get the exact position for every character inside a textflow?, also I'm having trouble with the TLF documentation, is there anny documentation that shows more on how to work with it in actionscript rather than mxml, im looking to write my own component and perhaps not use richtexteditor if i don't need to.
Many thanks!
Edit: i finally think i figured out how to get each characters position in the textflow:
private function getCharPosition():void {
for (var i:int=0; i<=textController.flowComposer.numLines; i++) {
var textFlowLine:TextFlowLine = textController.flowComposer.findLineAtPosition(i);
var textLine:TextLine = textFlowLine.getTextLine();
trace('number of atoms in this line: ' + textline.atomCount);
for (var j:int=0; j<=textLine.atomCount; j++) {
try {
trace(textLine.getAtomBounds(j));
} catch (e:Error) {
trace('error');
}
}
}
}
This returns an error that's why i have try and cache, i have tried to change textLine.atomCount to -1 but that wont work either. Now i don't know what character exactly that i have the position for. Lots of figuring out yet...
You can use some of these steps which (among other things) allow to determine character's bounds.
What about your second question you can refer to the following documentation and/or some samples.
protected var categoryXML:XML;
protected var categoryArr:ArrayCollection;
protected var categoryList:IList;
for (var i:int=0;i<getLength(categoryXML.category);i++) {
trace(categoryXML.category[i].name);
categoryArr[i] = categoryXML.category[i].name;
}
I'm having trouble with this bit of code...
The trace here works great, and I get the response I expect, but when I try to add it to the categoryArr variable, I get yelled at and told it's null.
What could cause the difference here?
Thanks!
did you try to create your ArrayCollection : categoryArr = new ArrayCollection(); ?
So, if you are getting that there is a null reference at that line, it is because categoryArr is probably null. You need to initialize it, like #www0x0k suggested.
I will also suggest that you probably don't want to use indexes in this way. It assumes too much about the length of the particular ArrayCollection without any bounds checking. Consider code like this instead:
categoryArr = new ArrayCollection();
for each(var category in categoryXML.category) {
trace(category.name);
categoryArr.addItem(category.name);
}
I'm getting Flex error #2007, right when the app starts up.
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/getChildIndex()
at mx.core::Container/getChildIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2411]
at mx.containers::ViewStack/set selectedChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\containers\ViewStack.as:557]
at property/parseUrl()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:8803]
at property/initBrowserManager()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:8749]
at property/___property_Application1_creationComplete()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:19]
I'm trying to get deeplinking to work properly. Bhasker Chari on the Adobe Flex forum was kind enough to help me with the code below:
private function parseUrl(e:BrowserChangeEvent = null):void {
var o:Object = URLUtil.stringToObject(browserManager.fragment);
var j:Object = o.view;
var f:String = String(j);
var c:String = f.replace(/-/g,"_");
var t:Container = mainViewStack.getChildByName(c) as Container;
mainViewStack.selectedChild = t;
}
Basically, I take the browserManager.fragment, convert it to a string, replace the dash with an underscore, convert it to a container, and use that to set the the selectedChild on the mainViewStack.
But, when it initializes, it says that there is no child parameter. How can I solve this problem?
Thank you.
-Laxmidi
Okay,
I figured it out. I need to add:
if(t!=null){mainViewStack.selectedChild = t}
else{mainViewStack.selectedIndex = 0}
The children hadn't been created, yet.
Thank you.
-Laxmidi