App crashes after tap on UITextField in iOS - ios

I created an app for iOS in VS with Xamarin. It works well both on iOS Simulator and real devices, but once I get a message from the user, that app crashes after a tap on UITextField. This is default iOS UITextField on the login screen. Strange, that this crash appears only on iPhone 6s with iOS v10.2.1. On iPhone with iOS >= v10.3 this crash doesn't appear.
This UITextField has only one event overriding
loginInput.EditingChanged += (s, e) =>
{
UITextField textInput = (UITextField)s;
if (textInput.Text.Length == 10)
{
textInput.ResignFirstResponder();
}
else if (textInput.Text.Length > 10)
{
char[] originalText = textInput.Text.ToCharArray();
char[] maskedText = new char[10];
for (int i = 0; i < 10; i++)
{
maskedText[i] = originalText[i];
}
textInput.Text = new string(maskedText);
textInput.ResignFirstResponder();
}
};
Also, I use UIKeyboard.Notifications.ObserveWillShow and UIKeyboard.Notifications.ObserveWillHide in ViewWillAppear overriding to translate the whole view depending on keyboard height. It's needed because otherwise, keyboard hides UITextField and user can't see, what he types.
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
UIKeyboard.Notifications.ObserveWillShow((s, e) =>
{
var r = UIKeyboard.FrameEndFromNotification(e.Notification);
keyboardHeight = r.Height;
_originalPosition = mainPageView.Center.Y;
if (keyboardHeight == 0)
{
keyboardHeight = r.Height;
}
Action keyboardShift = () => {
var xpos = mainPageView.Center.X;
var ypos = mainPageView.Center.Y - keyboardHeight;
mainPageView.Center = new CGPoint(xpos, ypos);
};
UIViewPropertyAnimator propertyAnimator = new UIViewPropertyAnimator(0.25, UIViewAnimationCurve.EaseInOut, keyboardShift);
propertyAnimator.StartAnimation();
});
UIKeyboard.Notifications.ObserveWillHide((s, e) =>
{
var r = UIKeyboard.FrameEndFromNotification(e.Notification);
keyboardHeight = r.Height;
if (keyboardHeight == 0)
{
keyboardHeight = r.Height;
}
Action keyboardUnShift = () => {
var xpos = mainPageView.Center.X;
var ypos = _originalPosition;
mainPageView.Center = new CGPoint(xpos, ypos);
};
UIViewPropertyAnimator propertyAnimator = new UIViewPropertyAnimator(0.25, UIViewAnimationCurve.EaseInOut, keyboardUnShift);
propertyAnimator.StartAnimation();
});
}
Hope somebody help me with this.

Related

I'm having problems zooming into images that are in rows of an UITableView in Xamarin.iOS

I have a tableView inside a tabView, and my rows in the tableView contain images. I would like to zoom into the said images (I put them inside a scrollView and set the max/min zoom and I set ViewForZoomingInScrollView), but it seems I can't get the zoom to trigger because they are small images 50x56 or some other gesture/event is interfeiring. I use the same zoom code on another part of my app and it works perfectly. Has anyone come across the same or similar problem or knows a possible solution?
EDIT:
protected DocumentBaseCell()
: base(UITableViewCellStyle.Default, new NSString("TableCell"))
{
...
documentImage = new UIImageView();
documentImage.Image = UIImage.FromBundle("LaunchImage");
documentImage.ContentMode = UIViewContentMode.ScaleAspectFit;
documentImage.Layer.ZPosition = 0;
imageScrollView = new UIScrollView();
imageScrollView.ClipsToBounds = false;
imageScrollView.ContentSize = new CGSize(50, 56);
imageScrollView.MaximumZoomScale = 8f;
imageScrollView.MinimumZoomScale = 1f;
imageScrollView.Add(documentImage);
imageScrollView.ViewForZoomingInScrollView += (UIScrollView sv) =>
{
imageScrollView.ContentSize = new CGSize(documentImage.Frame.Width, documentImage.Frame.Height);
return documentImage;
};
imageScrollView.DidZoom += (object sender, EventArgs e) =>
{
//(sender as UIView).Layer.ZPosition = 2000;
};
imageScrollView.ZoomingEnded += (object sender, ZoomingEndedEventArgs e) =>
{
(sender as UIScrollView).SetZoomScale(0f, true);
(sender as UIView).Layer.ZPosition = 0;
this.Layer.ZPosition = 0;
};
ContentView.Add(imageScrollView);
...
}
And this is the UpdateCell method:
internal virtual void UpdateCell(DocumentModel doc, string sup, string
docType, string user, string date, UIImage image)
{
if (image != null)
{
this.documentImage.Image = image;
}
...
}
The Frame is set aswell:
public override void LayoutSubviews()
{
base.LayoutSubviews();
imageScrollView.Frame = new CGRect(0, 2, 50, 56);
documentImage.Frame = new CGRect(0, 0, 50, 56);
}
I think you should give a frame to imageScrollView and documentImage, I download the official tableView sample project and add your code there, it zooms well.
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
imageScrollView.Frame = new CGRect(ContentView.Bounds.Width - 233, 5, 133, 133);
headingLabel.Frame = new CGRect(5, 4, ContentView.Bounds.Width - 63, 25);
subheadingLabel.Frame = new CGRect(100, 18, 100, 20);
imageView.Frame = imageScrollView.Bounds;
}
I uploaded a sample project here and you can check it.

Print WebView with multiple pages in Xamarin UWP

I am trying to print web page in xamarin forms. I am using DependencyService to print webview, which I have implemented in android successfully.
For Windows UWP,
I referred to this link:
https://forums.xamarin.com/discussion/91163/problem-with-printing-webview-in-uwp-phone
The approach used in this is printing only the first page of the webpage.
Edit :
I created an interface IPrint providing only the html source to the function.
public interface IPrint
{
void PrintAsync(string htmlSource);
}
In PrintAsync function (in Windows UWP project),
async void IPrint.PrintAsync(string htmlSource)
{
ViewToPrint.NavigateToString(htmlSource);
ViewToPrint.LoadCompleted += ViewToPrint_LoadCompleteAsync;
}
When WebView is completely loaded,
private async void ViewToPrint_LoadCompleteAsync(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
if (PrintDoc != null)
{
printDoc.AddPages -= PrintDoc_AddPages;
printDoc.GetPreviewPage -= PrintDoc_GetPreviewPage;
printDoc.Paginate -= PrintDoc_Paginate;
}
this.printDoc = new PrintDocument();
try
{
printDoc.AddPages += PrintDoc_AddPages;
printDoc.GetPreviewPage += PrintDoc_GetPreviewPage;
printDoc.Paginate += PrintDoc_Paginate;
bool showprint = await PrintManager.ShowPrintUIAsync();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
PrintDoc = null;
GC.Collect();
}
To add pages in PrintDocument,
private void PrintDoc_AddPages(object sender, AddPagesEventArgs e)
{
printDoc.AddPage(ViewToPrint);
printDoc.AddPagesComplete();
}
To implement multiple pages printing,
I referred this link : https://stackoverflow.com/a/17222629/6366591
I changed AddPages function to the following, but it doesn't seem to work for me.
private void PrintDoc_AddPages(object sender, AddPagesEventArgs e)
{
rectangleList = GetWebPages(ViewToPrint, new Windows.Foundation.Size(100d, 150d));
foreach (Windows.UI.Xaml.Shapes.Rectangle rectangle in rectangleList)
{
printDoc.AddPage(rectangle);
}
printDoc.AddPagesComplete();
}
You can find GetWebPages() function here.
List<Windows.UI.Xaml.Shapes.Rectangle> GetWebPages(Windows.UI.Xaml.Controls.WebView webView, Windows.Foundation.Size page)
{
// ask the content its width
var _WidthString = webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollWidth.toString()" }).GetResults();
int _ContentWidth;
if (!int.TryParse(_WidthString, out _ContentWidth))
throw new Exception(string.Format("failure/width:{0}", _WidthString));
webView.Width = _ContentWidth;
// ask the content its height
var _HeightString = webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollHeight.toString()" }).GetResults();
int _ContentHeight;
if (!int.TryParse(_HeightString, out _ContentHeight))
throw new Exception(string.Format("failure/height:{0}", _HeightString));
webView.Height = _ContentHeight;
// how many pages will there be?
var _Scale = page.Width / _ContentWidth;
var _ScaledHeight = (_ContentHeight * _Scale);
var _PageCount = (double)_ScaledHeight / page.Height;
_PageCount = _PageCount + ((_PageCount > (int)_PageCount) ? 1 : 0);
// create the pages
var _Pages = new List<Windows.UI.Xaml.Shapes.Rectangle>();
for (int i = 0; i < (int)_PageCount; i++)
{
var _TranslateY = -page.Height * i;
var _Page = new Windows.UI.Xaml.Shapes.Rectangle
{
Height = page.Height,
Width = page.Width,
Margin = new Windows.UI.Xaml.Thickness(5),
Tag = new Windows.UI.Xaml.Media.TranslateTransform { Y = _TranslateY },
};
_Page.Loaded += (s, e) =>
{
var _Rectangle = s as Windows.UI.Xaml.Shapes.Rectangle;
var _Brush = GetWebViewBrush(webView);
_Brush.Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill;
_Brush.AlignmentY = Windows.UI.Xaml.Media.AlignmentY.Top;
_Brush.Transform = _Rectangle.Tag as Windows.UI.Xaml.Media.TranslateTransform;
_Rectangle.Fill = _Brush;
};
_Pages.Add(_Page);
}
return _Pages;
}
WebViewBrush GetWebViewBrush(Windows.UI.Xaml.Controls.WebView webView)
{
// resize width to content
var _OriginalWidth = webView.Width;
var _WidthString = webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollWidth.toString()" }).GetResults();
int _ContentWidth;
if (!int.TryParse(_WidthString, out _ContentWidth))
throw new Exception(string.Format("failure/width:{0}", _WidthString));
webView.Width = _ContentWidth;
// resize height to content
var _OriginalHeight = webView.Height;
var _HeightString = webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollHeight.toString()" }).GetResults();
int _ContentHeight;
if (!int.TryParse(_HeightString, out _ContentHeight))
throw new Exception(string.Format("failure/height:{0}", _HeightString));
webView.Height = _ContentHeight;
// create brush
var _OriginalVisibilty = webView.Visibility;
webView.Visibility = Windows.UI.Xaml.Visibility.Visible;
var _Brush = new WebViewBrush
{
SourceName = webView.Name,
Stretch = Windows.UI.Xaml.Media.Stretch.Uniform
};
_Brush.Redraw();
// reset, return
webView.Width = _OriginalWidth;
webView.Height = _OriginalHeight;
webView.Visibility = _OriginalVisibilty;
return _Brush;
}
#Jerry Nixon's method worked well on my side. Since his code sample was posted on that thread about five years ago. For current UWP APIs, I just done a little changes(e.g, webView.InvokeScriptAsync). I also saw that you call the webView.InvokeScriptAsync method in your code. That's good. But you call the GetResults() method, I did not suggest you call GetResults() method. Because invoking javascript code sometimes will take you a lot of time. You might get the exception A method was called at an unexpected time.
Then, I also noticed that your printing flow is a bit of a mess. Please read Print from your app to learn the standardized printing process.
You could check the official code sample Printing sample for details.
The following was the updated code of your code snippet:
async Task<List<Windows.UI.Xaml.Shapes.Rectangle>> GetWebPages(Windows.UI.Xaml.Controls.WebView webView, Windows.Foundation.Size page)
{
// ask the content its width
var _WidthString = await webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollWidth.toString()" });
int _ContentWidth;
if (!int.TryParse(_WidthString, out _ContentWidth))
throw new Exception(string.Format("failure/width:{0}", _WidthString));
webView.Width = _ContentWidth;
// ask the content its height
var _HeightString = await webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollHeight.toString()" });
int _ContentHeight;
if (!int.TryParse(_HeightString, out _ContentHeight))
throw new Exception(string.Format("failure/height:{0}", _HeightString));
webView.Height = _ContentHeight;
// how many pages will there be?
var _Scale = page.Width / _ContentWidth;
var _ScaledHeight = (_ContentHeight * _Scale);
var _PageCount = (double)_ScaledHeight / page.Height;
_PageCount = _PageCount + ((_PageCount > (int)_PageCount) ? 1 : 0);
// create the pages
var _Pages = new List<Windows.UI.Xaml.Shapes.Rectangle>();
for (int i = 0; i < (int)_PageCount; i++)
{
var _TranslateY = -page.Height * i;
var _Page = new Windows.UI.Xaml.Shapes.Rectangle
{
Height = page.Height,
Width = page.Width,
Margin = new Windows.UI.Xaml.Thickness(5),
Tag = new Windows.UI.Xaml.Media.TranslateTransform { Y = _TranslateY },
};
_Page.Loaded +=async (s, e) =>
{
var _Rectangle = s as Windows.UI.Xaml.Shapes.Rectangle;
var _Brush = await GetWebViewBrush(webView);
_Brush.Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill;
_Brush.AlignmentY = Windows.UI.Xaml.Media.AlignmentY.Top;
_Brush.Transform = _Rectangle.Tag as Windows.UI.Xaml.Media.TranslateTransform;
_Rectangle.Fill = _Brush;
};
_Pages.Add(_Page);
}
return _Pages;
}
async Task<WebViewBrush> GetWebViewBrush(Windows.UI.Xaml.Controls.WebView webView)
{
// resize width to content
var _OriginalWidth = webView.Width;
var _WidthString = await webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollWidth.toString()" });
int _ContentWidth;
if (!int.TryParse(_WidthString, out _ContentWidth))
throw new Exception(string.Format("failure/width:{0}", _WidthString));
webView.Width = _ContentWidth;
// resize height to content
var _OriginalHeight = webView.Height;
var _HeightString = await webView.InvokeScriptAsync("eval",
new[] { "document.body.scrollHeight.toString()" });
int _ContentHeight;
if (!int.TryParse(_HeightString, out _ContentHeight))
throw new Exception(string.Format("failure/height:{0}", _HeightString));
webView.Height = _ContentHeight;
// create brush
var _OriginalVisibilty = webView.Visibility;
webView.Visibility = Windows.UI.Xaml.Visibility.Visible;
var _Brush = new WebViewBrush
{
SourceName = webView.Name,
Stretch = Windows.UI.Xaml.Media.Stretch.Uniform
};
_Brush.Redraw();
// reset, return
webView.Width = _OriginalWidth;
webView.Height = _OriginalHeight;
webView.Visibility = _OriginalVisibilty;
return _Brush;
}
I used the Printing sample and put my above updated code in it and do some relevant changes, then I could print all web pages successfully.

How do I remove gesture recogniser from a label in a UITableViewCell?

I've bottom toolbar in my ViewController and a TableView above it. The toolbar has a date label in the middle, and next and previous buttons on the left and right. based on the selected date tableview content changes..
Now TableViewCell contains a UILabel. I want to add Gesture to the label only if the selected day is today.
So I wrote in my cell update method
UITapGestureRecognizer gesture = new UITapGestureRecognizer();
gesture.AddTarget(() => HandleValueLabelClick());
if (source.parentController.selectedDateTime.Day == DateTime.Now.Day)
{
AddEditAction();
ValueLabel.AddGestureRecognizer(gesture);
}
else
{
ValueLabel.RemoveGestureRecognizer(gesture);
}
But the gesture remove if the selected date is not today, is not working. Any help is appreciated..
Edit:
public partial class ProgramCalendarCell : UITableViewCell
{
NSIndexPath indexPath;
ProgramVitalsCalendarTableSource source;
ProgramVital vital;
ProgramVitalCalendar calendar;
public ProgramCalendarCell (IntPtr handle) : base (handle)
{
}
public void UpdateCell(ProgramVital vital, ProgramVitalCalendar calendar, NSIndexPath indexPath, ProgramVitalsCalendarTableSource source)
{
this.source = source;
this.indexPath = indexPath;
this.vital = vital;
this.calendar = calendar;
InitVitalName();
InitVitalValue();
NewValueTextField.Hidden = true;
ValueLabel.Hidden = false;
UIView separatorLine = new UIView(new CoreGraphics.CGRect(0, 44, 1200f, 0.5f));
separatorLine.BackgroundColor = AZConstants.SeparatorColor;
ContentView.AddSubview(separatorLine);
UITapGestureRecognizer gesture = new UITapGestureRecognizer();
gesture.AddTarget(() => HandleValueLabelClick());
if (source.parentController.selectedDateTime.Day == DateTime.Now.Day)
{
AddEditAction();
ValueLabel.AddGestureRecognizer(gesture);
}
else
{
ValueLabel.RemoveGestureRecognizer(gesture);
}
}
void InitVitalName()
{
string name = vital.vitalName;
if (!String.IsNullOrEmpty(vital.unitName))
name += " (" + System.Net.WebUtility.HtmlDecode(vital.unitName) + ")";
VitalNameLabel.Text = name;
}
void InitVitalValue()
{
string value = "";
string color = "";
if (calendar != null)
{
value = calendar.values[0].value;
color = calendar.values[0].color;
}
UIHelper.SetVitalValueTileBackGround(ValueLabel, value, color);
}
void HandleValueLabelClick()
{
ValueLabel.Hidden = true;
NewValueTextField.Hidden = false;
NewValueTextField.BecomeFirstResponder();
}
void AddEditAction()
{
ValueLabel.UserInteractionEnabled = true;
NewValueTextField.ShouldReturn = (textField) =>
{
textField.ResignFirstResponder();
ValueLabel.Hidden = false;
NewValueTextField.Hidden = true;
Console.WriteLine("Row: " + indexPath.Row);
return true;
};
UIToolbar toolbar = new UIToolbar(new RectangleF(0.0f, 0.0f, (float)UIScreen.MainScreen.Bounds.Size.Width, 44.0f));
toolbar.BarTintColor = AZConstants.PrimaryColor;
toolbar.TintColor = UIColor.White;
toolbar.Items = new UIBarButtonItem[]{
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate {
Console.WriteLine("Row: " + indexPath.Row);
SaveReading();
NewValueTextField.ResignFirstResponder();
})
};
toolbar.BarTintColor = AZConstants.PrimaryColor;
toolbar.TintColor = UIColor.White;
toolbar.Translucent = true;
toolbar.SizeToFit();
NewValueTextField.InputAccessoryView = toolbar;
int vId = Int32.Parse(vital.vitalId);
if (vId == 20 || vId == 5 || vId == 496)
NewValueTextField.KeyboardType = UIKeyboardType.DecimalPad;
else
NewValueTextField.KeyboardType = UIKeyboardType.NumberPad;
}
async void SaveReading()
{
var hud = UIHelper.GetProgressHud(source.parentController.View, "");
hud.Show(animated: true);
Status status = await VitalHelper.postVitalValue(Constants.__IOS__, vital, NewValueTextField.Text, 0,
DateTime.Now.ToString("MM/dd/yyyy"), DateTime.Now.ToString("hh:mm tt"), "");
if (status.status)
{
source.parentController.FetchAndDisplayVitalValues();
}
else
{
new UIAlertView("Error", status.message, null, "OK", null).Show();
}
hud.Hide(animated: true, delay: 0);
}
}
It doesn't work 'cause you are removing a newly created gesture, not the gesture it already may have.
You must retrive the gestures array with ValueLabel.gestureRecognizers then remove each one with a for loop.

add sub view if it doesn't exist

on item click I add sub view (UIButton) to my supper view and want to remove it old one when user click again or just change title it isn't first click.
this is my custom renderer:
var text = new UIButton ();
protected override void OnElementChanged (ElementChangedEventArgs<Image> e)
{
base.OnElementChanged (e);
if (Control == null)
return;
if (this.Element != null) {
Original = (SpecLogoImage)this.Element;
}
TargetView = Control as UIImageView;
text.Layer.CornerRadius = 5;
text.Font = UIFont.FromName ("DIN Condensed", text.Font.PointSize);
text.TouchUpInside += delegate {
text.RemoveFromSuperview ();
};
var rec = new UILongPressGestureRecognizer (() => {
text.SetTitle(Original._hint, UIControlState.Normal);
text.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap;
text.SizeToFit ();
text.Frame = new CGRect ((UIApplication.SharedApplication.KeyWindow.Frame.Width / 2.0f) - (250 / 2.0f),
this.Superview.Superview.Superview.Frame.Height / 2.0f, 250, text.Frame.Height);
if (text.Superview==null) {
Animate (0.6f, () => {
this.Superview.Superview.Superview.AddSubview (text);
}, () => {
text.Layer.ZPosition = int.MaxValue;
});
}
});
text.SetTitleColor (UIColor.White, UIControlState.Normal);
text.BackgroundColor = UIColor.Black;
TargetView.UserInteractionEnabled = true;
TargetView.AddGestureRecognizer (rec);
}
}
every time user click Superview is null, what is the problem ?

Actionscript 2: Tween running extremely slow

I am using the following code to tween an movieclip once _global.choiceMade equals 1...
onClipEvent (load) {
import mx.transitions.Tween;
import mx.transitions.easing.*;
}
onClipEvent (enterFrame) {
if (_global.choiceMade == 1) {
var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
}
}
This is contained within each frame of the main timeline. The first time it runs fine but on the next frame it runs incredibly slow (takes about 12 seconds not 0.5 and is very choppy), if I then return to the first frame and run it again now this time it is extremely slow.
I can't work out why its doing this my CPU stays around 6-15% while its running so it can't be too demanding.
Updated to show rest of my code:
On main timeline have a frame each containing a movieclip. On the timeline of each of these movieclips contains:
//tint an object with a color just like Effect panel
//r, g, b between 0 and 255; amount between 0 and 100
Color.prototype.setTint = function(r, g, b, amount) {
var percent = 100-amount;
var trans = new Object();
trans.ra = trans.ga=trans.ba=percent;
var ratio = amount/100;
trans.rb = r*ratio;
trans.gb = g*ratio;
trans.bb = b*ratio;
this.setTransform(trans);
};//Robert Penner June 2001 - http://www.robertpenner.com
MovieClip.prototype.scaleXY = function(to){
this.onEnterFrame = function(){
this._alpha = to-(to-this._alpha)/1.2;
if(this._alpha > to-1 && this._alpha < to+1){
this._alpha = to;
delete this.onEnterFrame
}
}
}
scoreUpdated = 0;
Answer = 1;
_global.choiceMade = 0;
Buttons = new Array(this.buttonHolder.True, this.buttonHolder.False);
Answers = new Array(this.Correct, this.Wrong);
for (i=0; i<Answers.length; i++) {
Answers[i]._alpha = 0;
}
for (b=0; b<Buttons.length; b++) {
Buttons[b].thisValue = b;
}
In this movieclip there are two movieclip buttons (True and False) containing this code:
onClipEvent (enterFrame) {
this.onRollOver = function() {
this.gotoAndStop("over");
};
this.onRollOut = function() {
this.gotoAndStop("up");
};
this.onPress = function() {
this.gotoAndStop("down");
};
this.onReleaseOutside = function() {
this.gotoAndStop("up");
};
this.onRelease = function() {
this.gotoAndStop("down");
whichChoice = this;
_global.choiceMade = 1;
counter = 0;
};
if (_global.choiceMade == 1) {
this.enabled = false;
this._parent.scoreNow = _global.score;
this._parent.scoreOutOf = (this._parent._parent._currentframe)- 1 + ( _global.choiceMade);
if (thisValue == this._parent._parent.Answer && whichChoice == this) {
myColor = new Color(this);
myColor.setTint(0,204,0,13);
this._parent._parent.Answers[0]._alpha = 100;
this._parent._parent.Answers[0].scaleXY(100);
this.tick.swapDepths(1000);
if (counter == 0) {
_global.score++;
counter++;
}
}
else if (thisValue == this._parent._parent.Answer) {
myColor = new Color(this);
myColor.setTint(0,204,0,13);
this.tick.swapDepths(1000);
}
else if (whichChoice == this) {
this._parent._parent.Answers[1]._alpha = 100;
this._parent._parent.Answers[1].scaleXY(100);
myColor = new Color(this);
myColor.setTint(255,0,0,13);
this.cross.swapDepths(1000);
}
else {
myColor = new Color(this);
myColor.setTint(255,0,0,13);
myColor.setTint(255,0,0,13);
this.cross.swapDepths(1000);
}
}
}
The script at the top is on a movieclip these buttons are contained in called buttonHolder which does what it says, and tweens the buttons across the screen to reveal a next button once an answer is chosen.
From what I can see, as long as you have choiceMade == 1 you create a new effect! which is not ok. because in 1 sec at 15 fps you will have 15 tweens running :(
try yo set choiceMade = 0 or somehting else than 1
onClipEvent (enterFrame)
{
if (_global.choiceMade == 1)
{
_global.choiceMade = -1;
var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
}
}
Without seeing the rest of your code it's hard to see exactly what's going on. But it looks like you never change choiceMade and it continuously recreates the tween.
onClipEvent (enterFrame) {
if (_global.choiceMade == 1) {
var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
_global.choiceMade = 0;
}
}

Resources