facebook

Detecting a number in a image url (src): CLOSED

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #329777 Reply

    KadoBonux
    Member

    On a screen I want to display an image depending on the current image’s name and the selected navigator button.
    The images are player_1.png, player_2.png, player_3.png, ….
    The goal is to know which image is displayed by detecting the number, increase/decrease the number and display the image.
    This is the script I used to display the image of player #2 in the onclick action of my button :

    var myInt = 2;
    $(‘#m1-FCD_TeamContingentPlayer-Image_Player’).attr(‘src’,’images/Player_’ + myInt.toString() + ‘.png’);
    Then If I write
    var mySource = $(‘#m1-FCD_TeamContingentPlayer-Image_Player’).attr(‘src’);
    mySource is “undefined” (even if I leave the 1st 2 lines that display the image of player #2

    How can I detect a number in the image url?

    #329839

    Max87
    Member

    Hi KadoBonux,
    try set variable not in function, but globally – put var mySource outside of function and in your function just write
    mysource=$(‘#m1-FCD_TeamContingentPlayer-Image_Player’).attr(‘src’);
    I have similar problems very often and declaring variable as global mostly help.
    Let me know if this helped you.

    #329840

    KadoBonux
    Member

    Hi Max87,
    many thanks for your answer, I appreciate!
    A few minutes ago I found my mistake… In fact the first line

    var mySource = $('#m1-FCD_Team1ereContingentPlayer-Image_Player').attr('src');

    was followed by this one

    var posOfUSChar = mySource.indeOf('_');

    When executing the code the debugger indicates
    “Result of expression ‘mySource.indeOf’ [undefined] is not a function.” and I thought [undefined] was due to “mySource”.
    As I was really tired I did not pay attention to the real mistake : mySource.indexOf(‘_’); (“x” was missing)
    I also had problems because my pictures were in /images of main screen and not in /images of my second screen (called by main one)… and I was testing only the second screen (.mobi).
    With all those bugs fixed I can now read the index of my pages (second question I had) and then increase/decrease them as requested!!

    I quiet new with Javascript and I will continue to sweat!

    Once again many thanks for your time!

    #329841

    Max87
    Member

    Small bugs(f.e missing letters) are the worst 🙂
    I’m glad to hear, that you solved your problem.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Detecting a number in a image url (src): CLOSED

You must be logged in to post in the forum log in