Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Loading

1st Prize - Apple iPad


Answers by decyclone

  • Score
    10
    decyclone replied on 01-03-2011 07:50

    Closures at work here. Simply creating a local copy of "var c" inside the loop will solve the issue.

    public sealed class SomeType
    {
        public event EventHandler Triggered;
        public void Trigger()
        {
            // update state here
            var local = Triggered;
            if (local != null)
            {
                local(this, EventArgs.Empty);
            }
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            var st = new SomeType();
            var corners = new[] { "North", "South", "East", "West" };
            foreach (var c in corners)
            {
                var local = c; // Create a local copy
                st.Triggered += (s, a) => Console.WriteLine("{0} reporting ...", local); // Use that local copy instead of "c"
            }
            st.Trigger();
        }
    }
    

    A similar issue discussed here: http://stackoverflow.com/questions/271440/c-captured-variable-in-loop

  • Score
    2
    decyclone replied on 01-05-2011 07:47

    It can be done by adding a handler to following events:

    UIElement.KeyUpEvent
    UIElement.KeyDownEvent  
    UIElement.MouseLeftButtonDownEvent
    UIElement.MouseLeftButtonUpEvent
    UIElement.MouseWheelEvent
    UIElement.TextInputEvent
    UIElement.TextInputStartEvent
    UIElement.TextInputUpdateEvent
    

    Using following code:

    // set last argument to true if want to handle `handled` events
    AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseLeftButtonDown), false);
    

    On an element.

    For example for following handler:

    private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(String.Format("Sender: {0}, OriginalSource: {1}", sender, e.OriginalSource));
    }
    

    sender will be the element down below and e.OriginalSource will be the actual element that was directly under mouse.

    [NOTE: This example was created in Silverlight 4]

  • Score
    4
    decyclone replied on 01-07-2011 01:07

    PlaceHolder control forgets everything that it had on each postback (Stateless behavior). You have to remember it instead. Following code works:

    Int32 TextBoxCount
    {
        get
        {
            if (ViewState["TextBoxCount"] == null) ViewState["TextBoxCount"] = 0;
            return (Int32)ViewState["TextBoxCount"];
        }
        set { ViewState["TextBoxCount"] = value; }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    { }
    
    protected void Unnamed1_Click(object sender, EventArgs e)
    {
        TextBoxCount++;
    
        for (int i = 0; i < TextBoxCount; i++)
        {
            TextBox txt = new TextBox();
            PlaceHolder1.Controls.Add(txt);
        }
    }
    

    [NOTE: Above code is not perfect but proves the point]

Copyright © Rivera Informatic Private Ltd.