#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Manchester, United Kingdom
    Posts
    16
    Rep Power
    0

    Dynamically generate buttons (for page use)


    Right,
    The idea is to be able to dynamically add buttons to any page, by requesting a .swf file with params, for example:
    somedomain.com/thefile.swf?text=Submit&link=(...)

    Which would return a .swf that changes in width so all the text fits and a onrelease to go to the link.

    I've tried a lot to get this working, and searched a lot. But I'm still a newbie to AS and flash.

    Any help or an example would be greatly appreciated.

    Thanks in advance.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Toronto Canada
    Posts
    73
    Rep Power
    16
    if you're talking about calling dynamically sized and parameter fed swfs in an html page, I'd be inclined to take the swfObject js (available at http://blog.deconcept.com/swfobject/ ) and modify it so that the script in the div tag is a function (place it in the head or make it another external included js file so you can use in in multiple pages) , with the size and parameters are passed as arguments, and do a js function call from the spot you want the button to sit. That way, you use swfObject to embed properly, have flash detection, and be able to feed the flash size and arguments all in one happy package.

    note I haven't done this, but it should work.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Manchester, United Kingdom
    Posts
    16
    Rep Power
    0
    Yeah, swfObject is something im definatly going to use to embed the buttons.
    But what i was hoping for was the AS-side of it, where by passing these variables in it will ajust the size of the button, set the buttons text to the text param and set the button's link to the link param.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Toronto Canada
    Posts
    73
    Rep Power
    16
    the name of the parameter you pass ie: text= is the name of the variable in flash. So set up a dynamic textfield, set the textFieldName.text to that value, and then get to know the .autoSize = left , then check the textFieldName.textWidth value, and set the width of your button graphic accordingly. There are all kinds of helpful possibilities in the textField class.

    That'll do it.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Manchester, United Kingdom
    Posts
    16
    Rep Power
    0
    Thanks a lot, i'll try and see if i can get it working.
    Will reply soon.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Toronto Canada
    Posts
    73
    Rep Power
    16
    k I'l check back later.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Manchester, United Kingdom
    Posts
    16
    Rep Power
    0
    Any chance you could show me an example?
    I've tried a few things, like the autoSize and stuff, but i cant seem to get anything working. And then i tried to set the width manually by using the width and the font size, but that isnt working either.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Toronto Canada
    Posts
    73
    Rep Power
    16
    Originally Posted by The)TideHunter(
    Any chance you could show me an example?
    I've tried a few things, like the autoSize and stuff, but i cant seem to get anything working. And then i tried to set the width manually by using the width and the font size, but that isnt working either.
    assuming you have a dynamic textfield set up and named, you set the text to your passed paramter:
    yourTextField.text = yourParamterName;

    the line:

    yourTextField.autoSize = true;

    will ensure the textfield will size to the text being set to it.

    then get the size of the text from this property:
    yourTextField.textWidth

    use that to figure out what to size the button to, ie:

    yourButtonGraphicMovieClipName._width = yourTextField.textWidth;

    if you need some extra space on the graphic, you can alter it with:

    yourButtonGraphicMovieClipName._width = yourTextField.textWidth+5;

    in the flash help, searching textField will give all sorts of howtos on the basics of using textFields in flash it'd take me a while to retype all that out.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Manchester, United Kingdom
    Posts
    16
    Rep Power
    0
    Thanks.
    So:

    buttontext.text = urltext;
    buttontext.autoSize = true;
    button._width = buttontext.textWidth;

    Should work?
    If it should, then im doing something wrong.

    I have a button with the instance name button.
    And text inside that button with the instance name buttontext.
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Toronto Canada
    Posts
    73
    Rep Power
    16
    your scope is all wrong. You need to do a few basic tutorials in flash because without them you will definitely go in circles. And I don't know how to explain it better without that basic foundation.

    make sure you are referring to each object according to it's timeline.

    first, the button clip must be a movieclip, named. You must use the path to the textfield, if this code is on the root, you must use something like:
    button.buttonText.text to refer to it.

    If the button clip is a button type, you cannot access the textField to set it dynamically.

    Also, don't use 'button' for a name, it is a flash keyword (they will light up blue if it's a keyword).

    Comments on this post

    • The)TideHunter( agrees : Thanks for the continued support. Very helpful.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Location
    Manchester, United Kingdom
    Posts
    16
    Rep Power
    0
    Thanks for the support throughout, i'll try and mix some of the posts you've made and get things to work.
  22. #12
  23. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Toronto Canada
    Posts
    73
    Rep Power
    16
    if it helps at all, if it were me making a button clip to be reused as you want to, I would put the textfield right on the root, and place the the button graphic below it as a movieclip. Then I'd place the actions on root, take the passed variable, set it to the textfield, autosize it, grab it's textWidth so I know what to size the button graphic to, and set the _width of the button movieclip to it. You may need to add a few pixels to the end, because you'll likely want the graphic to extend some past the end of the text.

    If the button graphic can serve as a 'hit area', I would attach the button actions to that clip with code (not actually putting the code on the clip itself) in your actions keyframe, like ie:

    Code:
    yerButtonGraphicName.onRelease = function(){
                      getURL(yerPassedVariableWebPage);
    }
    You can do the same with onRollOver and onRollOut.

    Makes it easy and all the code is in one keyframe on root.

IMN logo majestic logo threadwatch logo seochat tools logo