Flash CS 5.5 resize radio button component - actionscript-3

How can I resize the radio button component that comes with Flash CS5.5?
The default look is quite small. The same applies to the radio button label which is also quite small.
Thanks in advance

You can find the graphical assets in the library. The folder will be "Component Assets" -> "RadioButtonSkins". Take note that there are many movie clips that comprise the various states of the radio button
As for the text/label portion of the radio button, you have to do that through code. Here is an example function you could have:
function styleRadioButton(rb:RadioButton, myTextFormat:TextFormat):void {
rb.setStyle("embedFonts", true); //if you want to use an embedded font
rb.setStyle("textFormat", myTextFormat); //set the text format
rb.setStyle("antiAliasType", AntiAliasType.ADVANCED); //if you want smoother looking fonts
rb.textField.autoSize = TextFieldAutoSize.LEFT; //if you want the label to automatically grow
}
So if you have an instance of a checkbox called myRadio, you could do this:
var textFormat:TextFormat = new TextFormat("Arial", 24, 0xFF0000); //make a red, 24px Arial text format
styleCheckBox(myRadio,textFormat);
Now, one easier thing you could also do is just place your radio button inside of a MovieClip or Sprite container and scale said container. To do this:
1 - place an instance of a radio button on the stage
2 - with the newly made instance selected, press F8 (or Modify -> Convert To Symbol)
3 - Scale the newly made movie clip

Related

Change color of clicked button AS3

I made a simple puzzle game in ROBLOX and I've decided to re-make it in AS3.
I've created a grid of buttons with click events, and now I need to change their color when clicked. I've currently got this:
trace("Button clicked:", event.currentTarget.id);
event.currentTarget.graphics.beginFill(0xA00000)
event.currentTarget.graphics.endFill()
the trace prints fine but the color doesn't change (causes no errors either)
The buttons are movie clips with labels inside.
beginFill and endFill are used to control the filled color of drawing commands like drawRect, they don't just change the fill of any arbitrary display object.
To change the color of a display object you can use ColorTransform:
var colorTransform:ColorTransform = new ColorTransform();
colorTransform.color = 0xA00000;
DisplayObject(event.currentTarget).transform.colorTransform = colorTransform;

How do I make a Progress bar (levelup bar) in flash cs6

I`m trying to build a simple game where you will view a map with 5 clickable objects.
When you click these objects you can navigate trough some pages and upon clicking the last button it returns to the map itself. Now everything is working as it should. Upon clicking this specific last button It has the following code.
jamenext2.addEventListener(MouseEvent.MOUSE_DOWN, gotomap2);
function gotomap2(event:MouseEvent):void {
gotoAndPlay("map2");
}
What I would like to have now is to have a bar on the Map itself, and when you have reached the button that has the above code attached, the bar increments by 20%, and so the same for the 4 other clickable buttons on the map. Upon 100% completion I would like it to play the next animation further on in the timeline.
I have tried the following, but I am not that good in writing code, and I`m not very sure where to place it exactly.
var total1 = 100;
_root.loaded1 = 0;
while(true) {
this.scaleX = _root.loaded1/total1;
}
_root.loaded1 = _root.loaded1 + 20;
gotoAndPlay("map2");
I have no idea on how to do this.
What your going to want to do is create a square or bitmap class for the progress bar. From there, create a square with a MouseEvent.MOUSE_DOWN for the buttons.
There is different ways of doing this. Judging from your sample code your using the timeline for scenes so you might want to put a button in there to scale in each scene.
You could size it at twenty percent and make it fully transparent and become viable on the first click. Then increment by twenty percent until a hundred percent visible. You could then also have another button that would roll back a page.
Mostly pseudo code but something like this:
(Example Reference link: http://www.actionscript.org/resources/articles/792/1/Drawing-Shapes-with-AS3/Page1.html )
import flash.display.Shape;
private var square:Shape;
main_method
{
square = new Shape();
//draw shape
square.graphics.beginFill(0x1111FF, 1);
square.graphics.drawRect(30, 30, 200, 200);
square.graphics.endFill();
square.alpha = .5;
addChild(square);
}
//somewhere in a MouseEvent.MOUSE_DOWN class
{
gotoAndPlay("map1");
}
}
It's also possible rather than creating a square in code to create a symbol instance name on the stage and and in the properties tab give it a name and reference it in code.

Actionscript 3, how do I make a menu appear by clicking a button, on the same frame?

So I have a button called manpb. When I click manpb, I want a menu to appear. The menu is a picture, but I can convert it into an object if this helps.
The best I can do is: Make a second frame with the menu, and insert the code inside the man_pb function:
gotoAndStop(2);
My problem is that I want the menu to appear on the same frame; then the menu will have buttons of his own. Any idea what to type inside the function below?
manpb.addEventListener(MouseEvent.CLICK, man_pb);
function man_pb(event:MouseEvent):void{
}
A big thank you!
The most intuitive solution might be to have your menu inside a MovieClip on the same frame. The menu buttons can also be placed within that menu MovieClip.
Simply convert your menu picture to a MovieClip (right-click, convert to MovieClip). Make sure that you select the MovieClip, and in the Properties panel give it an Instance Name, like menuMC or anything you want.
There are then a couple ways that you could handle making the menu appear only when you click the button.
1- Set the MovieClip's opacity to 0 by default, and then include this in your button function:
menuMC.alpha = 1;
thereby changing the MovieClip to fully opaque.
2- Make the MovieClip comprised of two frames, one empty frame that has a stop(); action, and one frame that contains your menu image and buttons. Then the button code would be:
menuMC.gotoAndStop(2);
3- Load the MovieClip dynamically from your library. See this for more information. edit: This is the approach that #DodgerThud is referring too, and is the more advanced but more comprehensive approach.
Use your Menu as an Object and add it to the MovieClip you want.
var menu:Menu = new Menu();//This is your Menu Symbol in your Library, you need to create one before you can use it
var manpb;//you could do the same thing for button, so you only need one symbol that has uses different labels
manpb.addEventListener(MouseEvent.CLICK, man_pb);
function man_pb(event:MouseEvent):void{
if(contains(menu)){//checking if "menu" already exists
removeChild(menu);//remove it from the displaylist
}else{
addChild(menu);//add it to the displaylist
}
}
In the Listener function you check if your current MovieClip (this should NOT be Button) already has a child that is menu. If it does, it removes the menu, otherwise, it will add the menu.
Don't forget to export your Menu for ActionScript.

Move MovieClip and everything it contains

I have a MovieClip called navbar and it has buttons over it. How do I connect the buttons to the MovieClip so that when the MovieClip is moved the buttons move with it? I have been able to make the navbar draggable but the buttons aren't dragged with it.
I have tried the following:
navbar.addChild(button1);
This just made the button disappear.
Your approach is correct: adding the buttons as children to the MovieClip will allow them all to be moved as one item.
The button disappearing could be any number of reasons, for instance x and y now relative to new parent (i.e. setting button y to 600 is now 600 pixels down from the navbar, not from the stage or old parent).
Try commenting out any properties you have set on the button and see if that resolves the issue, from there you can determine which property is causing the button to disappear.
So you should basically just have something like this:
var button1:Button = new Button();
navbar.addChild(button1);
If even with that minimal code doesn't result in the button displaying on the navbar, you'll need to post more code so that we can see where the problem is occurring.
you can calculate distance from Movieclip's X,Y to buttons and you can write a code like this:
var diff1:int = navbar.x - example_button1.x;
stage.addEventListener(Event.ENTER_FRAME, function(event:Event):void{
example_button1.x=navbar.x-diff1;
});
you can duplicate example_buttons and diff variables.
or you can startDrag() sametime with same event listener,
navbar.addEventListener(someEvent.some, function(event:someEvent):void{
MovieClip(root).navbar.startDrag();
MovieClip(root).example_button1.startDrag();
});
MovieClip(root) allows you to effect main stage. With this property you can effect an object from inside of navbar for example.
As you supposed, if you want the navbar and the buttons to act like a unique element you need to put buttons inside the navbar and not just over it.
The reason the button is disappearing is due to the fact that it has been put on the stage in Designer so, when you add it to navbar, you have it into two different display stacks, and that's not allowed.
You should put buttons inside the navbar in Designer, or export them for AS and then instance them dynamically, as follow:
var btn:Button1 = new Button1()
navbar.addChild(btn)
Class name Button1 is assigned in the MovieClip properties window of the Library, under Export for ActionScript.

How to make part of a text in a dynamic text field link to another frame just like hyperlinking to an html page?

I have a quite long classic text in a dynamic text field, with an UIScrollBar to scroll it. It has many references inside, part to sites in the web, part to other texts that I distributed in different frames of a movieclip with the text field inside. I have no problem linking to external websites from inside the text using the link and target fields in the properties panel. I have no problem using buttons to link to specific frames using functions with the gotoAndStop method. But I can't navigate to specific frames from selected words inside the text. Actually, I can't even navigate to files inside my computer using the link and target fields in the properties panel. Html tags are not being rendered, even with the "Render text as html" button clicked. I can't change the text to static because of the scroll bar. I can't also use invisible buttons behind the words because the scrolling would make them out of place. I don't see how a var could help me, cause it makes the text field show only the selected words. Anchors seem not to help also, since I can't target a file, but only http. Any ideas will be very welcome.
What you want is possible. But it comes with a little drawback thanks to a flash textfield bug. First your textfield text needs to be html text and also selectable. Then look here:
Textfield link event
public function TextField_event_link() {
myMP3 = new Sound();
var text:TextField = new TextField();
text.autoSize = TextFieldAutoSize.LEFT;
text.multiline = true;
text.htmlText = "Hello this is my little site. Click herefor the imprint. And here for the about page. And if you're coming so far, also here for the exit";
list.addEventListener(TextEvent.LINK, linkHandler);
addChild(list);
}
private function linkHandler(linkEvent:TextEvent):void {
switch(linkEvent.text)
{
case "imprint":
//display imprint
break;
case "about":
//display about
break;
case "exit":
//exit
break;
}
}
You can compare the event name in the handler and do your magic. If your text is not selectable this will not work. Dono if Adobe has fixed that issue with the latest player but this bugged me for years!