I am trying to upload a picture when a user clicks on a button using AS3. I have a button and a progress bar on the stage. This is the relevant code:
var myLoader:Loader = new Loader();
myPB.source = myLoader.contentLoaderInfo;
btn_one.addEventListener(MouseEvent.CLICK, btnImage);
function btnImage(event:MouseEvent):void{
myLoader.load(new URLRequest("MyPic.jpeg"));
addCild(myPB);
removeChild(myPB);
btn_one = null;
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishImage);
function finishImage(event:Event):void{
addChild(myLoader);
removeChild(myLoader);
btn_one = null;
When I execute the code this error appears Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found
Any ideas were I am going wrong?
var myLoader:Loader = new Loader();
//myPB.source = myLoader.contentLoaderInfo;
btn_one.addEventListener(MouseEvent.CLICK, btnImage);
function btnImage(event:MouseEvent):void{
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishImage);
myLoader.load(new URLRequest("MyPic.jpeg"));
//addCild(myPB);
//removeChild(myPB);
btn_one = null;
}
function finishImage(event:Event):void{
addChild(myLoader);
//removeChild(myLoader);
btn_one = null;
}
This should work. I don't know what you try to accomplish with adding a Child and removing the same child directly afterwards.
Hope this helps
Related
I'm actualy trying to add a markup annotation in a PDF with PDFKit, in Xamarin.Mac, so for OS X.
So my goal is to highlight permanently, as an annotation, a selected text in the PDF File, and save it to retrieve it when I open the file later.
The thing is, I can get the current selection and store it into a variable :
PdfSelection currentSelection = m_aPdfView.CurrentSelection;
And I can create an object PdfAnnotationMarkup :
//Create the markup annotation
var annot = new PdfAnnotationMarkup();
//add characteristics to the annotation
annot.Contents = currentSelectionText;
annot.MarkupType = PdfMarkupType.Highlight;
annot.Color = NSColor.Yellow;
annot.ShouldDisplay = true;
But I can't find, even though I checked a lot of different documentations, how to link the two of them.
There is no method giving the location of the currentSelection, or any hint to go in that direction.
Would anyone know of a way to make this possible ?
PS: I found that the subclasses of PDFAnnotation are deprecated on the Apple Developer Website , but not on the Xamarin Website, is there any way of knowing if both of them are related of entirely different ?
Thanks in advance for your help
EDIT : Here is the code I got and works perfectly. Thanks to svn's answers
//Get the current selection on the PDF file opened in the PdfView
PdfSelection currentSelection = m_aPdfView.CurrentSelection;
//Check if there is an actual selection right now
if (currentSelection != null)
{
currentSelection.GetBoundsForPage(currentSelection.Pages[0]);
//Create the markup annotation
var annot = new PdfAnnotationMarkup();
//add characteristics to the annotation
annot.Contents = "Test";
annot.MarkupType = PdfMarkupType.Highlight;
annot.Color = NSColor.Yellow;
annot.ShouldDisplay = true;
annot.ShouldPrint = true;
annot.UserName = "MyName";
//getting the current page
PdfPage currentPage = currentSelection.Pages[0];
//getting the bounds from the current selection and adding it to the annotation
var locationRect = currentSelection.GetBoundsForPage(currentPage);
getValuLabel.StringValue = locationRect.ToString();
//converting the CGRect object into CGPoints
CoreGraphics.CGPoint upperLeft = locationRect.Location;
CoreGraphics.CGPoint lowerLeft = new CoreGraphics.CGPoint(locationRect.X, (locationRect.Y + locationRect.Height));
CoreGraphics.CGPoint upperRight = new CoreGraphics.CGPoint((locationRect.X + locationRect.Width), locationRect.Y);
CoreGraphics.CGPoint lowerRight = new CoreGraphics.CGPoint((locationRect.X + locationRect.Width), (locationRect.Y + locationRect.Height));
//adding the CGPoints to a NSMutableArray
NSMutableArray pointsArray = new NSMutableArray();
pointsArray.Add(NSValue.FromCGPoint(lowerLeft));
pointsArray.Add(NSValue.FromCGPoint(lowerRight));
pointsArray.Add(NSValue.FromCGPoint(upperLeft));
pointsArray.Add(NSValue.FromCGPoint(upperRight));
//setting the quadrilateralPoints
annot.WeakQuadrilateralPoints = pointsArray;
//add the annotation to the PDF file current page
currentPage.AddAnnotation(annot);
//Tell the PdfView to update the display
m_aPdfView.NeedsDisplay = true;
A selection can span multiple pages. To get the location of a selection use:
var locationRect = currentSelection.GetBoundsForPage(currentSelection.Pages[0]);
You should be able to instantiate PdfAnnotationMarkup with bounds but the xamarin implementation does not expose that constuctor. But is does expose a bounds property
var annot = new PdfAnnotationMarkup();
annot.bounds = locationRect;
I have not tested this.
In our mvvm-application we are using mvxdialogfragments. Everything works fine under android 4.4, but the exact same code does not work with version 5 lollipop. There are no errors, no exceptions etc. they just don't show up :(
The Dialog is launched from a fragment with those lines:
var myDialog = new CalendarPickerView(){ViewModel = new CalendarPickerViewModel(){CurrentMonth = ViewModel.Day}};
myDialog.Show(Activity.SupportFragmentManager, "Date Selector");
and this happens in the dialogs create-method:
public override Dialog OnCreateDialog(Bundle savedState)
{
_singleLock = true;
ViewModel = MyViewModel;
EnsureBindingContextSet(savedState);
View view = this.BindingInflate(Resource.Layout.CalendarPickerView, null);
var myDialog = new Dialog(Activity, Resource.Style.CustomDialog);
myDialog.SetContentView(view);
MyViewModel.CurrentDate = DateTime.Now.Date;
var leftButton = view.FindViewById<ImageView>(Resource.Id.btn_left);
leftButton.Click += (sender, args) => MyViewModel.MonthBack();
var rightButton = view.FindViewById<ImageView>(Resource.Id.btn_right);
rightButton.Click += (sender, args) => MyViewModel.MonthForward();
cal = view.FindViewById<GridView>(Resource.Id.calendarGrid);
adapt = new CalendarAdapter(Activity);
cal.ItemClick += cal_ItemClick;
adapt.ViewModel = MyViewModel;
MyViewModel.PropertyChanged += MyViewModel_PropertyChanged;
cal.Adapter = adapt;
var saveBtn = view.FindViewById<LinearLayout>(Resource.Id.area_Save);
saveBtn.Click += ((s, a) =>
{
_singleLock = false;
Activity.RequestedOrientation = ScreenOrientation.Sensor;
Dismiss();
});
var abortBtn = view.FindViewById<LinearLayout>(Resource.Id.area_Cancel);
abortBtn.Click += ((s, a) =>
{
_singleLock = false;
Activity.RequestedOrientation = ScreenOrientation.Sensor;
Dismiss();
});
myDialog.SetCancelable(false);
myDialog.SetCanceledOnTouchOutside(false);
return myDialog;
}
If i use DialogFragment instead of MvxDialogFragment as baseclass for CalendarPickerView and remove all mvvm-related code in the create-method, everything works...
Strangely when debugging CalendarPickerView, the fragment ist listed under FragmentManager.Fragments but Dialog.IsShowing is false.
mvvm and xamarin are both the latest stable version by 28.11.2014. Did anybody else encounter this problem or do you have any idea what we could do?
thanks in advance!
I ran into the same problem and for me, the problem was not using MvvmCross or MvxDialogFragment. In my original and also in a separate test project I discovered the following reason for the problem:
It seems that - and I know that it sounds ridiculous - overriding the OnStart () method of DialogFragment even with a body that just includes the base.OnStart () call will prevent the dialog from appearing. Have a look at whether you're using OnStart () in your DialogFragment or somewhere in the inheritance hierarchy.
BTW, I suppose this is not necessarily related to Android 5 / Lollipop but that it is related to the ART runtime. I'll try to confirm this once I get to play with Android 5 device that does not make use of the ART runtime.
I've uploaded the sample project here which can be used to reproduce the issue:
https://github.com/nextmunich/XamarinDialogFragmentTest
I am getting images from Bing to display in my app. I followed Bing's instructions, I successfully retrieve the image's URLs, but for some reason, the emulator won't display them! Here's what I have
var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/"));
var accountKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
var imageQuery = bingContainer.Image("porsche", null, null, null, null, null, "Size:Medium");
imageQuery.BeginExecute(new AsyncCallback(this.ImageResultLoadedCallback), imageQuery);
Then, I get my images and try to set them here:
var imageQuery = (DataServiceQuery<Bing.ImageResult>)ar.AsyncState;
var enumerableImages = imageQuery.EndExecute(ar);
var imagesList = enumerableImages.ToList();
List<String> imList = new List<String>();
while (imList.Count != 3)
{
Bing.ImageResult tr = imagesList.First<Bing.ImageResult>();
if (tr.ContentType == "image/jpeg")
{
imList.Add(tr.MediaUrl);
}
imagesList.RemoveAt(0);
}
image1.Source = new BitmapImage(new Uri(#imList[0]));
image2.Source = new BitmapImage(new Uri(#imList[1]));
image3.Source = new BitmapImage(new Uri(#imList[2]));
When I debug, the process seems to just stop on those three last lines where I set the source.
Alright, after two days of frustration, I found out you cannot access the UI thread from an async callback. VS wasn't giving any errors, yet the images were not showing. An async callback runs alongside the main UI thread, so it can't access or change the elements in the UI. The easy workaround just involves wrapping the lines of code that access the UI like this:
Dispatcher.BeginInvoke(() =>
{
image1.Source = new BitmapImage(new Uri(#imList[0]));
image2.Source = new BitmapImage(new Uri(#imList[1]));
image3.Source = new BitmapImage(new Uri(#imList[2]));
});
It works now!
Are you sure MediaUrl is returning proper urls to images? What if you would use some hardcoded urls to images in the imList list, would the images load properly in image1, image2 and image3? The point i am getting to is that perhaps the quality of the data is incorrect. That is, though your query executes well, MediaURL is not containing a properly formatted URL.
Also, what is the exception you get when the debugger stops?
I am trying to get my flash application to send a request back to the webserver so that it can get some information. So far after reading on stackoverflow for a while and on the net I have some code written, but its not quite working right. I need just a little help tying it all together.
Here is the controller for my webserver
//
// POST: /Home/HoneyPot
[HttpPost]
public ActionResult HoneyPot(bool GetData)
{
//ViewBag.
return View();
}
Here is the ActionScript code that is supposed to be making the request.
// get dynamic page element information
var myData:URLRequest = new URLRequest("http://localhost:59418/HoneyPot");
myData.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.Input = "GetData=true";
myData.data = vars;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, gotPostData_Spiral);
loader.load(myData);
function gotPostData_Spiral(anEvent:Event):void
{
var postData = anEvent.target.data.myVar;
}
Right now when I run the flash code I get this output back:
Error opening URL 'http://localhost:59418/HoneyPot'
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query
string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
Thank you for the help
Instead of:
vars.Input = "GetData=true";
try:
vars.GetData = "true";
After quite a lot of debugging, I've refined a complicated Managed EWS problem down to the following two simple-ish test cases. The first one works, the second one fails:
var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Id } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)
var bindResults = ews.BindToItems(findResults.Select(r => r.Id), new PropertySet { EmailMessageSchema.Sender });
// Sanity check
Assert.AreEqual(1, bindResults.Count());
// The results I care about
Assert.AreEqual("David Seiler", bindResults[0].Sender.Name);
Assert.AreEqual("david.seiler#yahoo.com", bindResults[0].Sender.Address);
One might try to cut out the BindToItems() call, and use FindItems() directly:
var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Sender } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)
// This part still works fine
Assert.AreEqual(1, findResults.Count());
// So does this
Assert.AreEqual("David Seiler", findResults[0].Sender.Name);
// ...but this fails! Sender.Address is null
Assert.AreEqual("david.seiler#yahoo.com", findResults[0].Sender.Address);
Can anyone tell me where I've gone wrong? It really seems, from the documentation, as though this should work. Not all properties can be read through FindItems(), it's true, but those properties usually throw when I try to access them, and anyway there's a list of those properties on MSDN and Sender isn't on it. What's going on?
Actually I don't know why, but in the second option, it only load basic information of the sender like the name, but not the Address.
If you want to load all the sender properties but do not want to bind the full message you can add the following line before the first assert
service.LoadPropertiesForItems(findResults.Items, new PropertySet(EmailMessageSchema.Sender));