Navigation to other page using User Control - windows-store-apps

How can we navigate to other page on click on button in user control in windows store app? I tried by making a new frame object and calling navigate method, but no luck till yet.
thanks.

The Frame is a ContentControl that hosts the pages. If you want to navigate back and forth between pages you need to use a single Frame control. The default one is created in the App class in the default Visual Studio templates. You can save the instance reference of that Frame like by having a static property on the App class like: public static Frame RootFrame { get; private set; } and then set it where it is constructed - App.RootFrame = new Frame(). Then you can navigate simply by calling App.RootFrame.Navigate().

Related

Windows Phone 8.1 (runtime) additional data in OnMapTapped event

I am trying to create a Windows Phone 8.1 (Runtime) app that has a Map Control on it. I would like to attach additional data to the OnMappedTapped event or a way to grab an assigned Location ID when someone clicks on the MapIcon. Is this possible?
Yes. If you want to do something when someone clicks on a MapIcon (pushpin), then add a tap to the map and then do a search for elements that intersect the touch point using the Map.FindMapElementsAtOffset method: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.maps.mapcontrol.findmapelementsatoffset.aspx
or the Map.FindSubElementsForTouchTargeting method: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.uielement.findsubelementsfortouchtargeting.aspx
When it comes to storing or associating data to a pushpin, I like to store my data in the standard Tag property as that's something I've been doing for a while with WPF and Silverlight. You will notice that the MapIcon/MapElement classes do not have a Tag property, however they are DependancyObjects which meanswe can easily add custom properties to these classes. Here is a simple extension I often use in my WP apps to add a Tag property to these classes.
public static class MapElementExt
{
public static readonly DependencyProperty TagProperty = DependencyProperty.Register("Tag", typeof(object), typeof(MapElement), new PropertyMetadata(null));
}
You can then set this value like this:
pushpin.SetValue(MapElementExt.TagProperty, MyPinData);
Personally, when it comes to pushpins I normally don't mess with the MapIcon/MapElement classes and just create a UIElement for my pushpin. By doing this I can easily have a lot more control over creating my pushpin and can also easily add Tap events. You can specify the location for a UIElement like this:
MapControl.SetLocation(pushpin, MyGeopoint);
And then add the pushpin to the Map.Children property.
If you want to get the coordinates for a randomly selected point on a map through a touch event you can take the pixel coordinates from the tap event and pass them through the Map.GetLocationFromOffset method. For example:
MyMap.Tapped += (s, e) =>
{
Geopoint loc;
MyMap.GetLocationFromOffset(e.GetPosition(MyMap), out loc);
};

How could I compile the code for this Flash tutorial?

I started reading this tutorial: http://active.tutsplus.com/tutorials/actionscript/creating-a-reusable-flash-uploader-with-actionscript-3-0-and-php/
I'm using FlashDevelop, and I pasted the full code into an ActionScript file. The errors I'm receiving are like this:
C:\Users\tempus\Documents\uploaderas\Uploader.as(30): col: 4 Error: Access of undefined property select_btn.
select_btn.addEventListener( MouseEvent.CLICK, browse );
^
C:\Users\tempus\Documents\uploaderas\Uploader.as(31): col: 4 Error: Access of undefined property progress_mc.
progress_mc.bar.scaleX = 0;
...
I understand that the errors appear because the objects have not been declared ( and they appear to be instantiated from somewhere ), but I don't understand how/what should I include to declare them. Could you point me towards a solution?
It's because the buttons are created in the Flash IDE (as the tutorial was meant to be compiled using the Flash IDE). Since the buttons don't exist in the code aspect you get that error.
You can either create the elements yourself via code, or use the Flash IDE and export a swc/swf of the neccessary UI elements and include that in your flashDevelop project. I'm assuming you'll want to do the latter -
in the Flash IDE, open the .fla, open the library panel, find the progress asset, right click it and bring up the properties. Check the "Export For ActionScript" option, then in the 'Class' field give it a unique name like "SelectBtn". Do the same for the 'progress' asset (only a different class name like 'ProgressBar'). Go to the flash publish settings, and on the flash tab select 'export swc'. publish the file and place the published swc in your flash Develop project folder (traditionally the lib folder of your project).
In Flash Develop, right click your swc and choose 'Add To Library'. (You may need to right-click again and go to options and choose the include completely option). Now you can access those classes you setup in Flash. Then in your code, declare and initialize the display assets:
public var select_btn:SelectBtn = new SelectBtn();
public var progress_mc:ProgressBar = new ProgressBar();
You'll also need to do that textField too. It would be easiest just to do it in your code though.
public var label_txt:TextField = new TextField();
Keep in mind you'll need to manually position and use addChild on all three elements this way. If you want to keep the positioning that's in flash, just select all the elements on the stage and press F8 to convert them to a MovieClip. Then in the library setup linkage the same as the others and give it a class name of something like "DisplayAssets" and export a new swc. Then your code would look like this:
public var select_btn:Sprite;
public var progress_mc:Sprite;
public function Uploader(){
var displayAssets:DisplayAssets = new DisplayAssets();
addChild(displayAssets);
select_btn = displayAssets.select_btn;
progress_mc = displayAssets.progress_mc;
//the rest of the code
}

Flex Mobile persist view data

I built a simple hello world app to check out the Flash Builder 4.5 mobile capabilities.
Here's how it works:
The Default View asks for name in an textinput and has a continue button
When you click the continue button it pushes a new view in the viewNavigator which just displays "Hello " + name in a label.
When you click anywhere in this view, it pops a view (i.e. itself) from the viewNavigator, to go back to the default view
I see only 1 issue with this:
When I get back to the default view, it is in its initial state, i.e. the textInput is blank. It seems as if the viewNavigator created a new view of the default view's class and pushed this, instead of just removing the top view and displaying the previous one.
I see this being especially problematic for programs which display data in a grid and you can click the data to view the detail...when you get back, the grid will be empty.
Any ideas or gotchas to solve this?
EDIT:
Project name: HelloWorld
Code below:
HelloWorldDefaultView.mxml
protected function button1_clickHandler(event:MouseEvent):void {
navigator.pushView(HiView, tName.text);
}
HiView.mxml
protected function view1_clickHandler(event:MouseEvent):void {
navigator.popView();
}
protected function view1_creationCompleteHandler(event:FlexEvent):void {
lblHello.text="Hello " + data;
}
Screenshots
Initial screen
Screen 2
Clicking on screen 2 gets us back to initial screen. Notice the blank textInput
Have you tried to set destructionPolicy="never" and then
protected function button1_clickHandler(event:MouseEvent):void {
data = tName.text;
navigator.pushView(HiView, tName.text);
}
to store the data in current View's data - before changing to another one?
That's the way it is supposed to work for mobile applications.
Check out this article: Flex 4.5 (Hero) – Persistant Data in MobileApplication
As they write:
Each time a View is removed from the display list (via popView() or pushView()) its instance is destroyed, but its data model is stored in memory.
In order to save session state for a View, you must modify the data property. This property will be requested when destroying the current instance of the View class. And the data property value will be assigned back to a newly created instance of the same View class when navigating back to that view.

how to access class from embedded swf

I am trying to get an instance of a specific class from an embedded swf, it so happens the class I need is also the Default Application extending Sprite for the swf. I am able to do this successfully if I load the swf however I want to embed it instead.
The class I want to load is also extending a custom interface. Here is what I have tried but is not working:
[Embed(source="resources/MySwf.swf")]
private var MySwf:Class;
private function someFunction() : void
{
var inst:ISomeInterface = new MySwf() as ISomeInterface;
}
I appreciate any pointers.
Thanks.
Docs for embedding are here:
http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html
You should be able to do something like:
[Embed(source='resources/MySwf.swf', symbol='TheExportNameInMyFlaLibrary')]
public var MySwf:Class;
Personally, I prefer to use the Flash IDE publish settings to be have Export as SWC checked. That way, you can just drop the SWC into your FlashBuilder projects' lib folder and be done. Don't have to worry about manually setting each class up like this.

How can I access a function in one class from another AS3?

I have a AS3 MP3 player. The player class is called Mp3PlayerFrontEnd and controls the play and pause buttons. The playlist class is called PlaylistBoxItem and loads the track names into a playlist from XML. On each line of the playlist is a download button. When the download button is pressed, I want the player to pause. I thought I could just _player.pause(); from the playlist class but it doesnt work.
So my question is... How do I access the function in the MP3 player class from the playlist class?
I did not make this, I purchased it. I asked the guy who made it for help and he responded back...
"Normally you will just have to get access to the Mp3Player instance in PlaylistListboxItem class and call pause() on it in download function. I guess the easiest way to achieve this is to create a public static instance of a holder class that could be used access the player from wherever in code."
I do not know how to make a public static instance or where to put it.
Would I need to make a new class?
Where would I import it from?
How would I write the function?
Thanks.
Rich
whatever class is in control of everything needs a reference to your player.
So if your play list class is where you want to use play/pause/etc in the constructor add a place for a reference to the mp3player.
public class PlayListBoxItem
{
private var myMp3Player:Mp3Player;
// the class constructor
public function PlayListboxItem(myMp3Player:Mp3Player)
{
this.myMp3Player = myMp3Player;
}
}
now anywhere in the play list class you can access your mp3 player with myMp3Player.start() .stop(), .whatever public functions are there.
Make sure start and stop are public functions.