Flash AS3 ComboBox Dropdown Hover Color - actionscript-3

Hi everyone I am currently working on designing a flash program using adobe flash cs6 and as3. I cannot for the life of me figure out how to change the dropdown default light blue hover color in a comboBox component. I have changed all the other colors I need but that. Also I was able to change the font color when hovered over using the code below.
This is merely a design constraint and isn't affecting my program in any other way except for uniformity. Any help would be GREATLY appreciated!
import fl.events.*;
import fl.managers.*;
import fl.controls.*;
import fl.controls.listClasses.*;
stop();
var standard = new TextFormat();
standard.color = 0x000000;
StyleManager.setStyle("standard",standard);
var hover_color = new TextFormat();
hover_color.rollOverColor = 0xff0000;
StyleManager.setStyle("hover_color",hover_color);
StyleManager.setComponentStyle(ComboBox,"textFormat",StyleManager.getStyle("standard"));
StyleManager.setComponentStyle(TextInput,"textFormat",StyleManager.getStyle("standard"));
// comboBox labelField
StyleManager.setComponentStyle(CellRenderer,"textFormat",StyleManager.getStyle("standard"));
FGOne_cb.dropdown.addEventListener(ListEvent.ITEM_ROLL_OVER, rollOverListener);
FGOne_cb.dropdown.addEventListener(ListEvent.ITEM_ROLL_OUT, rollOutListener);
function rollOverListener(e:ListEvent)
{
var cr:CellRenderer = e.target.itemToCellRenderer(e.item) as CellRenderer;
cr.setStyle("textFormat",StyleManager.getStyle("hover_color"));
}
function rollOutListener(e:ListEvent)
{
var cr:CellRenderer = e.target.itemToCellRenderer(e.item) as CellRenderer;
cr.setStyle("textFormat",StyleManager.getStyle("standard"));
}

While it looks like you're trying to this by code. In FlashPro, you can style all the component skins by editing their symbols.
They can be found in your library under Component Assets
The specific one you're looking for is likely under Component Assets -> Shared -> focusRectSkin
Or maybe the comboBox_downSkin

Related

Multiple TextField's in Animate CC? Can't add second TextField

I have a very simple apps with LocalConnection between them. One button in client and one Dynamic Text on server. When I pushing my button on client then text in server are changing, everything works good. But if I add static text in server then my dynamic text stop working (not changing). How is it possible? Checked its 5 times, just adding static text ruined my app.
Sry, for my English, Im not fluent speaker.
p.s Woorking in Animate CC
p.p.s. feels that is very simple solution here but checked it in google and didnt found any answers :(
SERVER
import flash.net.LocalConnection;
var conn:LocalConnection = new LocalConnection();
conn.client = this;
conn.connect("data");
function recieve_data(unfO:String):void {
unfOne.text = unfO;
}
CLIENT
import flash.net.LocalConnection;
import flash.events.MouseEvent;
var conn:LocalConnection = new LocalConnection();
var unfOned:int = 0;
unfOne.addEventListener(MouseEvent.CLICK, unfOne_send);
function unfOne_send(e:MouseEvent):void {
unfOned++;
conn.send('data', 'recieve_data', unfOned);
unfOne_caption.text = unfOned.toString();
}
The problem is in Font, by default it was Open Sans and I should change it to arial or do Font Embeding.

How do I allow user to select tint amount in Flash Professional using ActionScript 3?

So I was in the middle of making a type of test program where I would take parts of a shirt and the user could customize it with different colors.
While I was doing that I realized it wasn't realistic as there was absolutely no fade with the color picker tool (code shown below).
Is there any way to allow the user to use possibly a slider to change the level of tint on the color(s) being used on the shirt?
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
import flash.geom.ColorTransform;
var mycolor:ColorTransform = new ColorTransform();
cp.addEventListener(ColorPickerEvent.CHANGE,colorChanger);
function colorChanger(event:ColorPickerEvent):void{
mycolor.color = cp.selectedColor;
mc2.transform.colorTransform = mycolor;
}
import fl.events.SliderEvent;
import fl.controls.Slider;
var slider:Slider=new Slider();
slider.maximum=100;
slider.value=100;
addChild(slider);
slider.addEventListener(SliderEvent.THUMB_DRAG,changeAlpha);
function changeAlpha(event:SliderEvent):void{
mycolor.alphaMultiplier=slider.value/100;
mc2.transform.colorTransform = mycolor;
}
Check this: flashandmath.com/howtos/tint
Very useful site, not only for tint! It's a big shame the authors don't really update it anymore. (but they still love flash, which is cool :o) )
You only need to use mc2.alpha = slider.value/100 to change it.

embedding a font in a swf using as3

I have a project using flash (and AIR for android and eventuall iOS) for translating some phrases. Although most fonts are fine there are some that I have to load after the user has chosen the languages. Over a year ago I generated a couple of swf files (Bengali and Urdu) and put them on my web server. The flash application then loads them when required and everything is OK...
However as I am nearing implementing the project I thought I should generate the swf files for the other languages that are in the pipeline and for some reason I can't manage it! Needless to say I have misplaced (tidied) the original AS3 source for the two fonts I have done.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class ArabicF extends Sprite
{
[Embed(source = "trado.ttf",
fontName = "ArabicX",
fontFamily = "ArabicY",
fontWeight = "normal",
fontStyle = "normal",
mimeType = "application/x-font",
advancedAntiAliasing="true",
embedAsCFF="true")]
public static const ArabicZ:Class;
}
}
This has expanded from a much simpler form as I added things to get it to work and I must have tried all permutations of true and false. I load the swf ok but then can't extract the class. With the two fonts I embedded before the swf class and the parameter all have the same name and they work fine (i.e.
Urdu.swf
then later:
var FontClass:Class = evt.target.applicationDomain.getDefinition("Urdu") as Class;
and then
Font.registerFont(FontClass.Urdu);
in the calling .as application with the above Arabic.swf I try
trace("1 Arabic "+evt.target.applicationDomain.hasDefinition("ArabicF"));
trace("2 Arabic "+evt.target.applicationDomain.hasDefinition("Arabic"));
trace("3 ArabicX "+evt.target.applicationDomain.hasDefinition("ArabicX"));
trace("4 ArabicY "+evt.target.applicationDomain.hasDefinition("ArabicY"));
trace("5 ArabicZ "+evt.target.applicationDomain.hasDefinition("ArabicZ"));
but all return false
PS also tried generating the Arabic.swf using fontswf.bat which again seems to make a very similar swf file which is loaded but I can't extract the class from it
PPS I'm using flashdevelop and the font swf are set up as AS3 standard project compiler options.
I don't use Flash Develop, but perhaps I can offer some perspective from my implementation.
If I wanted to embed Arial, the embedding swf would "Export for ActionScript" the embedded font. In its document class, use registerFont() as below:
Font.registerFont(Arial);
Like every other swf, you'd use a Loader to import it into your runtime, and at that point, the font will be available to your global table. You can query the complete list of registered fonts using enumerateFonts().
var fontList:Array = Font.enumerateFonts();
for (var i:int = 0; i < fontList.length; i++) {
trace(fontList[i].fontName);
}
Assuming we've got a TextField called "txt", you can then implement that font with setTextFormat() like so:
var format:TextFormat = new TextFormat();
format.font = "Arial";
txt.embedFonts = true;
txt.antiAliasType = AntiAliasType.ADVANCED;
txt.setTextFormat(format);
txt.defaultTextFormat = format;
A disclaimer from Adobe on the use of these last two settings:
"When you apply a TextFormat object to a text field using the
TextField.defaultTextFormat property or the TextField.setTextFormat()
method, only its defined properties are applied. Use the
TextField.defaultTextFormat property to apply formatting BEFORE you
add text to the TextField, and the setTextFormat() method to add
formatting AFTER you add text to the TextField."
As I said before, my workflow doesn't utilize Flash Develop, but rather Flash IDE to embed the fonts into the swfs. Your results may vary, but be aware you must set embedFonts to true, or it won't respond to your embedded font. I've lost hair on that issue before.
Hope that helps. Cheers,
OK In case someone else runs into similar problems this is stage one of the answer (really the answer to my original question) still have to sort out how to get the font to be used in the flash.font.engine apparatus!
The critical parts are:
Point #1. the embedded font swf must have a name that doesn't clash with ANY name registered in the calling script. Bizzare and (as far as I could search) undocumented. i.e. I have a list of languages uploaded via xml services to an xml object and that includes for instance 'English' however the font loading doesn't work until I make the loadable font file into 'EnglishF.swf' The obvious choice of just 'English.swf' fails. So my embedded font source is now called EnglishF.swf and reads:
package
{
import flash.display.Sprite;
import flash.text.Font;
import flash.system.Security;
Security.allowDomain("*");
/**
* ...
* #author patrick
*/
public class EnglishF extends Sprite
{
[Embed(source = "Kingthings Exeter.ttf",
fontName = "EnglishF",
fontFamily = "EnglishF",
fontWeight = "normal",
fontStyle = "normal",
mimeType = "application/x-font",
advancedAntiAliasing="true",
embedAsCFF="true")]
public static var myFont:Class;
}
}
and the using script goes:
private function fontLoaded(evt:Event):void {
var FontClass:Class
if (evt.target.applicationDomain.hasDefinition(font1Name)) FontClass = evt.target.applicationDomain.getDefinition(font1Name) as Class;
else if (evt.target.applicationDomain.hasDefinition(font2Name)) FontClass = evt.target.applicationDomain.getDefinition(font2Name) as Class;
try {
Font.registerFont(FontClass.myFont);
trace("successfully loaded " + FontClass);
} catch (err:Error) {
trace("couldn't register font "+FontClass.myFont+" =>"+err);
}
}
The line in the embedded script about security is because of point #2: the registerFont doesn't work across domains. In fact the Security.allowDomain() didn't work and to debug this I have had to copy/paste the swf files on the PC and change the loader.load(URLRequest()) accordingly
There is still an issue that although the font is registered and claims to be compatible with the flash.text.engine TextElement requirements it still fails to be used as in:
_tl = new Array();
var block:TextBlock = new TextBlock();
var font:FontDescription = new FontDescription(fontName);
var formt:ElementFormat = new ElementFormat(font, fontSize);
//following gives 'true EnglishF'
trace(FontDescription.isFontCompatible(fontName,"normal","normal"), formt.fontDescription.fontName);
formt.color = colr;
var span:TextElement = new TextElement(text, formt);
block.content = span;
_tl[0] = null;
_tl[0] = block.createTextLine(null, width);
var tl:TextLine;
// after here justification and addition lines
I will post something if and when I sort out why this doesn't work (Unless some kind person does it for me!)

away3d change 3ds mesh material on run-time

I'am trying to figure out how to change material on loaded 3ds object/mesh during run-time after mouse click.
(Away3D 3.5/3.6)
3ds object is loaded with Loader3D:
//global mesh variable and view3d
var my_mesh:Mesh;
var view:View3D = new View3D();
//creating a parser with initial material
var max3ds_parser:Max3DS = new Max3DS();
max3ds_parser.material = new WireColorMaterial(0xFF0000);
var loader:Loader3D = new Loader3D();
loader.addEventListener(Loader3DEvent.ON_SUCCESS, onSuccess);
loader.loadGeometry("myMesh.3ds", max3ds_parser);
addChild(view);
addEventListener(Event.ENTER_FRAME, onEnterFrameRenderScene);
function onSuccess(e:Loader3DEvent):void{
my_mesh = Mesh(e.loader.handle);
view.scene.addChild(my_mesh)
}
function onEnterFrameRenderScene(e:Event):void{
my_mesh.rotationY += 15;
view.render();
}
So, after all this the 3ds object is added to the scene with initial material (WireColorMaterial) applied with parser object. But now I want to change the initial material after mouse click, so:
stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void{
//start FAIL here:
my_mesh.material = new WireframeMaterial(0x000000);
//end FAIL
trace("clicked!");
trace(my_mesh.material)
}
After the mouse click nothing changes in the view, my_mesh spins as it did with the initial material on. But the trace material shows that the new material was indeed applied.
Is there any other way to do this, or is there some kind of a way to refresh the scene to make it use the new material? Or refresh the view? Or should you somehow parse my_mesh again? Cheers.
I would recommend importing your models via Prefab3D. This will allows you to pre-process all these assets in a visual tool.
I either use the awd format or just export meshes as AS3 classes. Export as AS3 classes also compresses that data with the rest of you assets in the swf, a nice little bonus :)

How to run an animation from within another class in Actionscript 3.0

I'm new to ActionScript 3.0 and I am trying to work my way around Object Orientated Programming.
I've designed an application where there are 3 buttons on the stage and a logo. What I want to happen is when a button is clicked, the logo will fade out. Now I understand I need to manipulate the alpha properties of the logo but not sure how I would run the code once the button is clicked. I have my Main.as file loading the properties of the application. So once the FLA file runs, Main.as sets up the buttons and the logo. Now the buttons are put into a display holder and run from menuHolder.as which in turn gets the design of the buttons from button.as - so far with me?
To keep my code clean I have seperated my code into their own files (the design of the buttons into its own .as file, the arrangement of the menu buttons into its own .as file, the logo creation into its own .as file) so that the Main.as file just acts as a loader for placing everything into location on the stage.
So my question is that I want to create an animation for the logo (a fade out animation) where the code would be stored in say animationFade.as for example. Then when a button is clicked, the animation plays and the corresponding page is navigated to.
Here is my code for the setup of the menuBottons.as:
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFormat;
public class menuButtons extends Sprite
{
private var aboutMeBtn:button;
private var galleryBtn:button;
private var contactMeBtn:button;
public function menuButtons()
{
aboutMeBtn = new button();
aboutMeBtn.y = 0;
aboutMeBtn.label = "About Me";
addChild(aboutMeBtn);
aboutMeBtn.addEventListener(MouseEvent.CLICK, onButtonClick);
galleryBtn = new button();
galleryBtn.y = 75;
galleryBtn.label = "Gallery";
addChild(galleryBtn);
galleryBtn.addEventListener(MouseEvent.CLICK, onButtonClick);
contactMeBtn = new button();
contactMeBtn.y = 150;
contactMeBtn.label = "Contact Me";
addChild(contactMeBtn);
contactMeBtn.addEventListener(MouseEvent.CLICK, onButtonClick);
}
public function onButtonClick(event:MouseEvent):void
{
//code to initiate the animationFade.as file
}
}
}
it's this //code to initiate the animationFade.as file that i cannot grasp. It may be something very simple but my head seems to be spinning!
Hopefully I have provided enough information. Like I say I am just learning at the minute and trying to build up slowly.
Thank you
The best way to do this would be to dispatch an event from your button click function. Then, create a listener in your Main.as file that handles the event and tells the logo to fade out.
Maybe something like:
From menuButtons.as
public function onButtonClick(event:MouseEvent):void
{
dispatchEvent(new Event("hide_logo", true));
}
You can read up on the Event Class documentation to learn more about the parameters.
From Main.as (after you create your menuButtons instance)
menuButtonsInstance.addEventListener("hide_logo", hideLogoHandler);
function hideLogoHandler(e:Event):void {
// Fade out logo
TweenLite.to(logo, 1, {alpha:0}); // requires TweenLite
}
This example requires TweenLite from Greensock.
On a side note, for best practice your class names should start with an uppercase character. So "menuButtons" class would be "MenuButtons". Then, instance names would start with a lowercase character. Makes it easier to read if you do something like:
var menuButtons:MenuButtons = new MenuButtons();