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 Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon
Accepted Solution

QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

I am looking to put an event listener into my application to listen for a SWIPE_DOWN event, that will make the ActionBar visible from false. This is so I can have a menu in my application. I looked everywhere and it completly looks like my code is right. I even copied and pasted a sample code from some one else to see if theres would work and I got the same error I got. The error I get is: 1120: Access of undefined property showMenu. I put my code below if anyone can find anything wrong with it or why this isnt working for me. Thanks in advance!

 

<fx:smileyfrustrated:cript>

<![CDATA[

 

import flash.display.Sprite;

import flash.events.MouseEvent;import qnx.events.QNXApplicationEvent;

import qnx.system.QNXApplication;

 

private function showMenu(event:QNXApplicationEvent):void{

actionBarVisible = true

}

 

QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_DOWN, showMenu);
]]>

</fx:smileyfrustrated:cript>

Please use plain text.
Developer
rhgills
Posts: 39
Registered: ‎01-13-2011
My Device: Not Specified

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

[ Edited ]

You need to include the line where you add the event listener inside a function. If that file is a view, you would want to include that line in an event handler for view activate, as below:

 

<s:View viewActivate="initView(event)">

 

initView is simply:

 

private function initView(e:ViewNavigatorEvent):void

{

QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_DOWN, showMenu);

}

 

If that mxml file is an Application do the same with creationComplete instead of

viewActivate. In that case, the type of event passed to your handler would be a FlexEvent instead of ViewNavigatorEvent.

 

Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

Hey, Thanks for the reply. I am new to Flash Builder and programming, so this may seem stupid of me to not know. I think I understand what you are saying, but I still get the same error. It is a ViewNavigatorApplication. I put all my code below for what I though you meant to change it to. Sorry for all the dumb questions for you but this is what I thought needed to happen.

 

 <?xml version="1.0" encoding="utf-8"?>

<s:View  xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

actionBarVisible="true" tabBarVisible="true" title="EPC" 

viewActivate="initView(event)">

<fx:smileyvery-happy:eclarations>

<!-- Place non-visual elements (e.g., services, value objects) here -->

</fx:smileyvery-happy:eclarations>

 

<fx:smileyfrustrated:cript>

<![CDATA[

import flash.display.Sprite;

import flash.events.MouseEvent;

import qnx.events.QNXApplicationEvent;

import qnx.system.QNXApplication;

import spark.events.ViewNavigatorEvent;

 

private function initView(e:ViewNavigatorEvent):void{

}

private function showMenu(event:QNXApplicationEvent):void{

actionBarVisible = true

}

]]>

</fx:smileyfrustrated:cript>

 

</s:View>

Please use plain text.
Developer
rhgills
Posts: 39
Registered: ‎01-13-2011
My Device: Not Specified

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

No worries, no question is a dumb question. Should be as below with changed parts in bold. Make sure you save the document - this lets flash builder know you want it to build your project again - and let me know if it compiles.

 

 

 <?xml version="1.0" encoding="utf-8"?>

<s:View  xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

actionBarVisible="true" tabBarVisible="true" title="EPC" 

viewActivate="initView(event)">

<fx:smileyvery-happy:eclarations>

<!-- Place non-visual elements (e.g., services, value objects) here -->

</fx:smileyvery-happy:eclarations>

 

<fx:smileyfrustrated:cript>

<![CDATA[

import flash.display.Sprite;

import flash.events.MouseEvent;

import qnx.events.QNXApplicationEvent;

import qnx.system.QNXApplication;

import spark.events.ViewNavigatorEvent;

 

private function initView(e:ViewNavigatorEvent):void{

QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_DOWN, showMenu);

}

private function showMenu(event:QNXApplicationEvent):void{

actionBarVisible = true;

}

]]>

</fx:smileyfrustrated:cript>

 

</s:View>

 

 

Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

Thank you so much yes it compiled fine no errors I didnt release the Evenet listener had to be in that function, Im not to sure why I need that function there but I am going to look into it. Thanks again for all the help!!!!! Now I wish there was a way to test the code in the Simulator. Anyway thanks again!!!

Please use plain text.
Developer
rhgills
Posts: 39
Registered: ‎01-13-2011
My Device: Not Specified

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

Good to hear and you are welcome. Although I haven't used the simulator in a while I do believe you can simulate a swipe down event by dragging down from the empty area in the simulator window where the top bezel would be into the visible area. Also, you might find this document helpful: http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_2.html

 

In particular:

 

All ActionScript in the block is added to the enclosing file's class when Flex compiles the application.

Statements and expressions are allowed only if they are wrapped in a function.

 

 

 

 

Please use plain text.
New Contributor
unexplored
Posts: 2
Registered: ‎09-09-2011
My Device: Playbook
My Carrier: None

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

[ Edited ]

Hi, 

 

I have a somewhat similar issue in that I want to use a single event accross multiple views. I managed to get it working in a view, but that means I have to duplicate the code for each view I am creating. 

 

Basically I am looking for a solution on how to implement this event in the main MXML file where the ViewNavigatorApplication is located.

 

Here is what I have so far:

 

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
							xmlns:s="library://ns.adobe.com/flex/spark" 
							xmlns:mx="library://ns.adobe.com/flex/mx"
							creationComplete="createMenu(event)"
							firstView="views.TestAppView" xmlns:utils="utils.*">
	
	<fx:Declarations>
		
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import caurina.transitions.Tweener;
			
			import mx.events.FlexEvent;
			
			import qnx.events.QNXApplicationEvent;
			import qnx.system.QNXApplication;
			
			// Registers the drop down menu for PB application
			protected function createMenu( event:FlexEvent ):void
			{
				QNXApplication.qnxApplication.addEventListener( QNXApplicationEvent.SWIPE_DOWN, pullDownMenu );				
			}
			
			private function pullDownMenu( event:QNXApplicationEvent ):void
			{
				trace( "Menu pulled down" );
				Tweener.addTween(slideMenu, {y: 0, time: 0.5, transition: "linear"});
				
				
				/** 
				 * add the mouse listener to hide the menu when the user clicks
				 * outside of the menu area
				 */				
				
				stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);
			}
			
			// Hide menu when the screen is touched outside menu
			private function onStageMouseClick( e:MouseEvent ):void
			{
				/** if the user clicks outside of the menu area, hide the menu */				
				if (mouseY > slideMenu.height)
				{
					Tweener.addTween(slideMenu, {y: -slideMenu.height, time: .3, transition: "linear"});					
					stage.removeEventListener(MouseEvent.CLICK, onStageMouseClick);
					trace( "Menu went up" );
				}
			}
			
		]]>
	</fx:Script>
	<s:navigationContent>
		<utils:Menu id="slideMenu">
			
		</utils:Menu>
	</s:navigationContent>
</s:ViewNavigatorApplication>

 

 and here is the file for utils.Menu:

 

package utils
{
	import flash.display.*;
	import flash.display.Shape;
	import flash.geom.*;
	
	import spark.core.SpriteVisualElement;
	

	[Bindable]
	public class Menu extends SpriteVisualElement
	{
		public function Menu()
		{
			super();
			
			this.width  = 1024;
			this.height = 150;
			this.y = -150;
			this.id = "MainMenu";

			var spreadMethod:String = SpreadMethod.PAD;
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [0xFF0000, 0x0000FF];
			var alphas:Array = [1, 1];
			var ratios:Array = [0x00, 0xFF];
			var matr:Matrix = new Matrix();
			
			matr.createGradientBox( 800, 20, 0, 0, 0 );	
			this.graphics.clear();
			this.graphics.beginGradientFill( fillType, colors, alphas, ratios, matr, spreadMethod );        
			this.graphics.drawRect( 0,0,this.width,this.height );
			this.graphics.endFill();
		}
	}
}

 

Though I can see the trace is printing, nothing happens on the UI, I tried to play with Y coordinates still nothing happens.

 

I am not very sure as were to use it in the <s:ViewNavigatorApplication>. In a <s:View> i was just able to put it as a UI element and everything was fine, but I try to use it for the entire app.

 

Thanks a lot for any suggestions

Please use plain text.
New Contributor
unexplored
Posts: 2
Registered: ‎09-09-2011
My Device: Playbook
My Carrier: None

Re: QNXApplicationEvent.SWIPE_DOWN, with Flex 4.5

Never mind guys I found the solution :smileyhappy:

 

Basically if you want to have a drop down menu for all your views, you need to get a handle to the navigator object inside the main MXML file and do the same thing like per individual view. Here is the code needed inside the ViewNavigatorApplication tag:

 

<fx:Declarations>
		<!-- Menu is a custom object inheriting from SpriteVisualElement -->
		<utils:Menu id="slideMenu">			
		</utils:Menu>
</fx:Declarations>

.............................

// Registers the drop down menu for PB application
			protected function createMenu( event:FlexEvent ):void
			{
				QNXApplication.qnxApplication.addEventListener( QNXApplicationEvent.SWIPE_DOWN, pullDownMenu );
				navigator.addElement(slideMenu);
			}


private function pullDownMenu( event:QNXApplicationEvent ):void
			{
				trace( "Menu pulled down from MAIN file" );
				Tweener.addTween(slideMenu, {y: 0, time: 0.5, transition: "linear"});
									
				navigator.stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);
			}			
			
			// Hide menu when the screen is touched outside menu
			private function onStageMouseClick( e:MouseEvent ):void
			{
				/** if the user clicks outside of the menu area, hide the menu */				
				if (mouseY > slideMenu.height)
				{
					Tweener.addTween(slideMenu, {y: -slideMenu.height, time: .3, transition: "linear"});					
					stage.removeEventListener(MouseEvent.CLICK, onStageMouseClick);
					trace( "Menu went up" );
				}
			}

 

Now things  are working for me as desired, I can get the same menu from any view without duplicating code

 

Please use plain text.