Announcement

Collapse
No announcement yet.

Setting Text On Page Load

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Setting Text On Page Load

    Hi everybody,

    I'm trying to set the text in a text field when I load a page in my Scaleform menu. For instance on the main page the user would click Profile, it would go to the Profile page and populate the text fields with their profile data. Unfortunately what I'm noticing is that I seem to be trying to set the text fields before they're initialized. While I could set the data to load when the Widget is initialized, if the data gets updated(which it will) or they go back to that page after leaving it, the fields will be blank since the Widget isn't being initialized a second time, to my knowledge. I tried something like this:

    Code:
    RootMC.GotoAndStop("Profile");
    Name = GFxClikWidget(RootMC.GetObject("Name", class'GFxClikWidget'));
    Name.SetText(userName);
    in the code that loads the profile but that doesn't seem to be working, either. Does anybody have any idea as to what I can do here?

    Thank you

    #2
    It sounds like you have different 'menus' one different parts of the timeline in your SWF. Then to open your 'profile menu' you're going to the 'profile menu' bit of the timeline. This isn't really the best way to do things. It's much better to have each menu be a separate movieclip, all displayed, then toggle their visibility as you need. This way you can set up the defaults for your text etc in the init of your MoviePlayer class once, and it'll stick.

    Eg:

    Code:
    // Inside GFxMoviePlayer class, it's best to ensure your menus are all split into separate classes for code management
    var GFxProfileMenu ProfileMenu;
    
    // Inside GFxMoviePlayer class, call from HUD when you initialize the GFxMoviePlayer
    public function Init()
    {
      RootMC = GetVariableObject("_root");
      ProfileMenu = GFxProfileMenu(RootMC.GetObject("ProfileMenu", class'GFxProfileMenu'));
      if (ProfileMenu != None)
      {
        ProfileMenu.Init();
        ProfileMenu.SetVisible(false);
      }
    }
    
    
    
    // Inside GFxProfileMenu class
    var GFxClikWidget NameTF;
    
    // Inside GFxProfileMenu class, called from the GFxMoviePlayer class
    public function Init()
    {
      NameTF= GFxClikWidget(GetObject("Name", class'GFxClikWidget'));
      NameTF.SetText("WhatevsBro");
    }
    
    
    
    // Now, whenever you need to switch to the profile menu, in the main GFxMoviePlayer class, you can just:
    public function ShowProfileMenu()
    {
      HideAllMenus();
      ProfileMenu.SetVisible(true);
    }
    This is more than just a style thing - what you're doing is causing flash to instantiate the instances of the MovieClips when they appear in the timeline, so you can't pre-set values. You can get around that with making instances in the timeline that are invisible etc, but IMHO, I'd just do the above.

    Comment


      #3
      Thanks. I'd tried something similar before but I didn't manage to get it working. Although I think I was actually loading the movie when I switched menus rather than loading all of them at start and switching visibility. The way you put it actually makes a lot of sense in terms of how it's done and is much less confusing than trying to decipher what came with UDK.

      Just to clarify, they're all movie clips in the same Flash file but each movie clip gets its own class and I turn them on and off as needed? And HideAllMenus is a function I would make that simply sets the visibility of all menus to false?

      Comment

      Working...
      X