Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Event handlers can't use namespaced functions? RSS

3 replies

Last post May 03, 2007 08:35 AM by luisabreu

(0)
  • lazycoder

    lazycoder

    Member

    14 Points

    5 Posts

    Event handlers can't use namespaced functions?

    May 02, 2007 05:39 AM | LINK

    I've got a script defined using "namespaces" like so

     

    player = {

        stop : "",

        play :""

    }

     

    player.stop = function(sender,args) {

        sender.findName("media").stop();

    }

    player.play = function(sender,args) {

        sender.findName("media").play();

    }

     

    XAML snippet

    <mediaElement x:Name="media" ... /> 

    <canvas MouseLeftButtonDown="player.stop" ... />

    <canvas MouseLeftButtonDown = "player.play" ... /> 

    But the canvas elements don't call those methods on clicks.

     

    If I pull those methods out of the player object and put them in the global object.

    e.g.

    function play(sender, args) { ... }

     AND if I call the player.play method from a global function, it is called correctly.

    e.g.

    function media_play(sender,args) { player.play(sender,args); }
     

    The functions are called correctly. Is this by design?
     

  • luisabreu

    luisabreu

    Participant

    1676 Points

    612 Posts

    Re: Event handlers can't use namespaced functions?

    May 02, 2007 11:37 AM | LINK

    hello.

    well, the previous version had the same problem. not sure on why that happens though...

  • Mark Rideout

    Mark Rideout

    Contributor

    2736 Points

    307 Posts

    Microsoft

    Re: Event handlers can't use namespaced functions?

    May 02, 2007 06:29 PM | LINK

    This is by design and won't change for 1.0. Events in XAML and Javascript do not understand object/function pointer and names. You can wire up the events programmatically in javascript using the addEventListner method.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"
  • luisabreu

    luisabreu

    Participant

    1676 Points

    612 Posts

    Re: Event handlers can't use namespaced functions?

    May 03, 2007 08:35 AM | LINK

    Hello Mark.

    hum...yes and no. This is a good option if you've got your xaml loaded and want to associate silverlight objects to js objects. If you're going on the other direction, ie, if you have js objects that inject xaml on a canvas, you'll need extra work to perform that kind of mapping (which is not very cool :( )