If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
tensioncore
Posts: 323
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers
Accepted Solution

removeChild in function

Hey guys, I'm having an issue with my function...


The function is called when a user inputs text in the field, and then hits "Shorten This!"


....and the function is working correctly, but it repeats itself overtop of itself on the stage, and I tried doing removeChild(varname); at the begining of the function, but alas if the function is being run for the first time, it gives me an error that varname doesn't exist!...stuuuuck.


I could optionally remove any said children once a user clicks into the text field to enter a new url, but I don't want to be taking the output away before they hit enter again....How do I figure this out?

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: removeChild in function

hey,

 

im not entirely sure what your function does. but i assume you are trying to erase the text field after the user inputs something and hits submit? what gets repeated? wat gets added? thanks!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
Harry_Dodgson
Posts: 151
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: removeChild in function

[ Edited ]

This isn't so bad.  I use something like this several places in my app.

 

if (varname != null)
  removeChild(varname);

EDIT: Forgot to mention that varname needs to be defined outside the function (globally) for this to work.

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide
Please use plain text.
Developer
tensioncore
Posts: 323
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: removeChild in function

[ Edited ]

The Function contacts the API and returns the results to the stage. Once the person hits Shorten This! the function contacts the API then does all the display (a bunch of textFields added to the stage)....


...SO if the person wants to shorten another address without leaving the application, they can just type into the field again and hit shorten This! again, however as of NOW it is adding children over top of what it already added...


...The children are being called within the function, so should I declare them before the function as var public HashTextField:TextField = new TextField(); ...?

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: removeChild in function

hey,

 

yeah i would just leave a textfield or label object in the place where it reports back the link location or confirmation and every time they it submit just update the text value on the object and it will "referesh" it with new text. that way you are reusing the object instead of adding a new one and removing an old one from the stage. hope that helps. good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
tensioncore
Posts: 323
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: removeChild in function

Can I do that by simply putting this in the function: urlHash.htmlText = "Text goes here"; - ?
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: removeChild in function

[ Edited ]

yes as long as you have the object urlHash already added to where you want people to see it. so everytime you set the htmlText property it will automatically update the text that shows up where the urlHash object has been added.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
tensioncore
Posts: 323
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: removeChild in function

[ Edited ]

I might not be doing this right...can you help please?


var urlTEXT:TextField = new TextField();
urlText.x = (x location);
urlText.y...etc
addChild(urlText); function APIconnect(evt:Event):void{
//DOES THINGS//
urlText.htmlText = "Example text";
}

...it still adds a new one when I run the function.

EDIT:I figured it out.....My vars were still within another function. so when I moved them out to the main function it worked!
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: removeChild in function

where are you placing the urlText textfield object declaration? is it outside the main function inside another function?

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
tensioncore
Posts: 323
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: removeChild in function

Yes! I was so confused, because it wasn't within that function anymore, but I guess it just kept getting added when theOTHER function it was in was run (which was only at application runtime - once)...which is odd. so yeah I took it out all together of any function...my bad. Thanks for your help JRab! You've been a great help with everything!
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Please use plain text.