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
New Contributor
turtlehat
Posts: 4
Registered: ‎03-28-2011
My Device: Pearl 8130

Re: Check if variable passed to view is defined

I would guess data is not set.

 

 

if (data == null) {
  trace("no data");
}

 

 

Developer
ajerman
Posts: 101
Registered: ‎03-18-2011
My Device: Playbook Simulator

Re: Check if variable passed to view is defined

That's an interesting thought actually. If no variables are passed, maybe the data parent as a whole is never even initialized. I'll check that and report back.

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Check if variable passed to view is defined

[ Edited ]

hey,

 

when pasing data via the navigator's push view method, you need to refer to the data in the new view as simply "data" as and not the actual variable name u sent into it from the other view. hope that clears things up. good luck!

 

Edit: Here is what the method structure looks like:

 

 

public function pushView(factory:Class, data:Object = null, transition:spark.effects:ViewTransition = null):void

 

 

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
Developer
ajerman
Posts: 101
Registered: ‎03-18-2011
My Device: Playbook Simulator

Re: Check if variable passed to view is defined

[ Edited ]

Okay, sorry, Flash Builder decided that the password to the simulator was suddenly wrong so I had to reboot the simulator. So, data is always defined, not just when I pass a variable, so that way of checking won't work.

 

Also, JRab, I tend to listen to you over most, but I'm not sure that's true. All the examples (all like 3 I found) showed data.<variablename> as the method to retreive. When running data.toString() through the trace, I get [object Object] as the output. data.selectedWeek shows the proper output when it's set though. Also, you could send multiple variables that the data object would contain, so there has to be some way to differentiate them. I bet data[0] would work though if that's what you mean.

 

Edit: No, data[0] doesn't work either. I thought it might put it in an array or something. Looks like the only way I see to do it is the way I have now. Pass null unless you're passing a variable, then you can check if it's defined.

Developer
berryawesome
Posts: 54
Registered: ‎12-22-2010
My Device: Not Specified

Re: Check if variable passed to view is defined

Ok. scratch what I said about the default parameter. I didn't realize you were using a built in method. My bad for not carefully reading the post.

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Check if variable passed to view is defined

hey ajerman,

 

i just double checked and the data field is in fact referred to as "data". What tutorial are you looking at? and also this is what you posted in your earlier post:

 

 

navigator.pushView(viewEnterTime,selectedWeek);

 

so whatever you send into there, is what you will get in return. it doesnt add that variable to any foreign data object as a property. so if you send in selectedWeek, thats what data becomes in the new view.

 

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
Developer
ajerman
Posts: 101
Registered: ‎03-18-2011
My Device: Playbook Simulator

Re: Check if variable passed to view is defined

Ahh, JRab, I figured it out now. I think the confusion came from the fact that the things I read showed them passing the variable like: navigator.pushView(viewEnterTime,{selectedWeek:selectedWeek}), but I was originally doing it as just (viewEnterTime,selectedWeek), as I posted. If you just use that, you're right, data just contains selectedWeek's value. But halfway through this thread I changed over to the other method, and then you access it as data.selectedWeek.

 

Not sure how I could use that though. data isn't null if I don't send a variable. It prints it's value as [object Object] if nothing is passed, so I probably could still use that as a check if it's set if I knew how to check that, but I'm not sure since it's not just a != null or != "" type thing and I'm new to this language.

 

As long as one way works though, I'm fine with passing a null. I just don't know about what I mentioned earlier about a pop, but that makes no difference in my app.

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Check if variable passed to view is defined

hey,

 

i dont like things unsolved :smileywink:

 

alrite so in the event that you arent passing any data value to the new view, how does your pushView method look like?

 

also how does it look when you do send data? we are going to tackle this. 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
Developer
ajerman
Posts: 101
Registered: ‎03-18-2011
My Device: Playbook Simulator

Re: Check if variable passed to view is defined

[ Edited ]

Oh, it's working now. To make it work, I'm just sending a null variable if I don't need to pass something...

 

In the event that I'm not sending data, I call the view like this:

 

 

navigator.pushView(viewEnterTime,{selectedWeek:null});

 

 

And when I do need to pass data, I just do:

 

 

navigator.pushView(viewEnterTime,{selectedWeek:selectedWeek});

 

 

Then I can check if data.selectedWeek is null or not.

 

This works well enough since I really only have two places that call that view, one sends a variable, one doesn't. In a different app that may or may not be the best solution, but for this app it works fine so I'm not too worried about it. I just initially wanted a way to call pushView without having to do anything for a variable if I didn't need one, and I think you were getting there with the suggestion of passing the variable without a label then just using "data" as my passed variable, but I don't know how to differentiate between it's unassigned "[object Object]" and an assigned value of what I passed to it, since neither are null.

 

Honestly though, either way works fine. I've got too many other things to fix up before the deadline as I cut it incredibly close, so I'll just leave it as is for now probably. I appreciate the help from everyone though. Learning with barely any documentation is difficult! :Wacko:

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Check if variable passed to view is defined

haha im just a nitpick :smileyhappy:

 

if you do run into the same problem or wondering about its efficiency and want to figure it out make sure to post about it in the forums. good luck on the rest of your app!

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