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
Posts: 20
Registered: ‎10-25-2010
My Device: Not Specified

MXML vs ActionScript

I've been playing at this SDK for a while (zero AS3 experience, so bare with me), and I'm a little confused about the MXML vs ActionScript.  I "get" that MXML renders a view, and I've even gotten it working on the playbook without difficulty.  Which is where I'm being thrown a loop.

 

I'm much more familiar with working in code, so I'd prefer to develop in ActionScript for now, but, I've decided to try out using Google Maps within the playbook.  When I define an MXML file using the sample on Google's AIR example, it opens up no problem in the playbook.

 

However, when I attempt to do the same deal in ActionScript, I end up with a blank canvas.

 

I've pasted my code below - I've found other sites that have this kind of stuff in AS3, but, it just doesn't seem to be working.

 

 

...
			var map:Map = new Map();
			map.key= "my-api-key";
			map.url = "http://code.google.com/apis/maps/";
			map.sensor = "false";
			map.height = 380;
			map.width = 500;

			map.x = (stage.stageWidth - map.width)/2;
			map.y = (stage.stageHeight - map.height)/2;
			
			addChild(map);
...

 

Is the MXML definition doing something else I'm not aware of?  Some .init() type method?

 

Just trying to resolve the discrepencies here, and any AS3 gurus input would be much appreciated!!

 

Thanks,

 

Dan Slack

 

Developer
Posts: 85
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

Hi dslack, do you get the MAP_READY event ?

add

map.addEventListener(MapEvent.MAP_READY, onMapReady);

before you do the addChild instructions and a onMapReady function somewhere that give you a feedback.

AS3 API should work exactly the way the Flex one work, everything is init once you do the addChild().


Fabien

Hope this helps,
Fabien

--
1. If you liked my post or found it useful please click on the white star and provide a Kudo!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!
Developer
Posts: 20
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

Fabien - 

 

Yeah, I stripped the code down a bit - I have a MAP_READY listener, as well as a MAP_PREINITIALIZE.  However, in the MAP_READY, I'm following the example from googles site, which just sets the center to a specified Lat/Lng.  And nothing seems to happen.  I'll modify it so that I do an alert of some kind.

 

Still not sure why its not being painted onto the screen however...

 

Thanks,

Dan

Developer
Posts: 85
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

Hey,

i'm not really sure but you can test it. Try using only the url parameter and not the key parameter or setting the url to "http://localhost/"


Fabien

Hope this helps,
Fabien

--
1. If you liked my post or found it useful please click on the white star and provide a Kudo!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!
Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

MXML is just markup for Actionscript based components. At the end of the day, everything is actionscript based, mxml just gives you the advantages that a markup language brings.

 

 

Can you paint anything to the screen? If it's just black, make sure that stage.nativeWindow.visible = true

Developer
Posts: 20
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

Ok, here is where I am now.

 

First, I've added some event handling, specifically handling MapEvent.MAP_INITIALIZE_FAILED.  When I take out the URL, or the API key, this event gets handled (I pop up an alert).

 

I did actually forget to add in stage.nativeWindow.visible = true, but, I was getting objects painted (a Label and a Button).  And when I added that in, it didn't make any difference on displaying the map.

 

What is strange is that the MapEvent.MAP_READY event doesn't seem to be thrown, when when I added logic to the button to output whether or not the map object was valid  (map.isLoaded()), it returns true??

 

I'm obviously missing something between what the markup is doing, vs the actionscript.  Maybe some other flag needs to be set?  

 

I'll keep trying in the meantime...

Contributor
Posts: 35
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

 


 

I did actually forget to add in stage.nativeWindow.visible = true, but, I was getting objects painted (a Label and a Button).  And when I added that in, it didn't make any difference on displaying the map.

 


 

Now that's weird. You must have it already defined in your -app.xml then??

 

You're not missing anything here related to mxml vs AS, if you're addChild() it to your document class it should be there.

 

1. Make sure you're adding the listeners before calling load

2. Make sure it's not offstage for some reason

New Developer
Posts: 63
Registered: ‎10-27-2010
My Device: 9900 and PlayBook
My Carrier: Rogers

Re: MXML vs ActionScript

How do you get MXML working on the playbook? I tried compiling some simple mxml and it wouldn't package for me.

-----------------------------------------------------------------------------
Apps:Beats Brainwave Entrainment - Awesome Timer - StarSlide - Save Santa
@jamiebeach
Developer
Posts: 85
Registered: ‎10-25-2010
My Device: Not Specified

Re: MXML vs ActionScript

@jbeach42

Instead of creating an actionscript project, create a Flex project. Select Desktop Air application, not web.  Target the BlackBerry AIR SDK.

You will get a mx:WindowedApplication tag. Turn it into mx:Application. Then you are ready to go, simply add a <visible>true</visible> to the application descriptor (the xml file that goes with your mail MXML), inside the initialWindow node

 

Hope this helps,

Fabien

Hope this helps,
Fabien

--
1. If you liked my post or found it useful please click on the white star and provide a Kudo!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!