views:

349

answers:

2

Ok I know this practically sounds elementary, but I don't understand what I'm not doing correct here.

I draw a simple rounded Rect

backing1.graphics.beginFill(bgColor);
backing1.graphics.lineStyle(borderSize, borderColor1);
backing1.graphics.drawRoundRect(position1, position1, sizeW-1, sizeH-1, cornerRadius1);
backing1.graphics.endFill();
//backing1.alpha = .1; //<-- tried setting alpha here didn't work

Then tried to add it into a movieClip

bgHolder = new MovieClip;
bgHolder.alpha = 0.1;
bgHolder.addChild(backing1);
addChild(bgHolder);

Still the color I'm using shows up at 100% :(

Full Background Class code

package display{
import flash.display.DisplayObject;
import flash.display.LineScaleMode;
import flash.display.JointStyle;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.utils.Timer;
import flash.text.TextField;
import flash.events.TimerEvent;

import model.*;

public class Background extends Sprite {
    private const position1:Number=0;
    private const position2:Number=1;

    public static var instance:Background;

    private var vTitle        :TextField = new TextField();
    private var tStorm        :TextField = new TextField();
    private var backing1      :Shape     = new Shape();
    private var backing2      :Shape     = new Shape();
    private var bgColor:uint=0xE8E7E7;
    private var borderColor1:uint=0xCCCCCC;
    private var borderColor2:uint=0xFFFFFF;
    private var borderSize:uint=1;
    private var cornerRadius1:uint=3;
    private var cornerRadius2:uint=1;
    private var sizeW:uint;
    private var sizeH:uint;
    private var bgHolder:MovieClip;

    public var titleString:String="";


    public function Background():void {
        if (stage) {
            init();
        } else {
            addEventListener(Event.ADDED_TO_STAGE, init);

        }
        instance=this;
    }

    private function init(e:Event = null):void {

        removeEventListener(Event.ADDED_TO_STAGE, init);

        bgHolder=new MovieClip  ;
        bgHolder.alpha=0.1;
        bgHolder.addChild(backing1);
        addChild(bgHolder);
        addChild(backing2);
        addChild(vTitle);
        addChild(tStorm);
    }

    public function drawBackground(w, h, mainTitle, color, otherText):void {
        sizeW=w;
        sizeH=h;
        bgColor=color;

        titleString=mainTitle;

        vTitle.defaultTextFormat=Fonts.PlayingTitle;
        vTitle.border=false;
        vTitle.embedFonts=false;
        vTitle.gridFitType="SUBPIXEL";
        vTitle.sharpness=100;
        vTitle.antiAliasType=flash.text.AntiAliasType.ADVANCED;
        vTitle.selectable=false;
        vTitle.mouseEnabled=false;
        vTitle.x=5;// 8-3=5 to align copy to video player
        vTitle.y=8;
        vTitle.width=sizeW-16;
        vTitle.height=30;
        vTitle.text=titleString;

        tStorm.defaultTextFormat=Fonts.TouchStormR;
        tStorm.border=false;
        tStorm.embedFonts=false;
        tStorm.gridFitType="SUBPIXEL";
        tStorm.sharpness=100;
        tStorm.antiAliasType=flash.text.AntiAliasType.ADVANCED;
        tStorm.selectable=false;
        tStorm.mouseEnabled=false;
        tStorm.x=8;
        tStorm.y=sizeH-20;
        tStorm.width=sizeW-16;
        tStorm.height=20;
        tStorm.text=otherText;

        backing1.graphics.beginFill(bgColor, 0.1);
        //backing1.graphics.beginFill(bgColor);
        backing1.graphics.lineStyle(borderSize, borderColor1);
        backing1.graphics.drawRoundRect(position1, position1, sizeW-1, sizeH-1, cornerRadius1);
        backing1.graphics.endFill();
        backing1.alpha=0.5;

        backing2.graphics.beginFill(bgColor);
        backing2.graphics.lineStyle(borderSize, borderColor2);
        backing2.graphics.drawRoundRect(position2, position2, sizeW-3, sizeH-3, cornerRadius2);
        backing2.graphics.endFill();
    }

    public function switchTitle(sentText):void {
        titleString=sentText;
        vTitle.text=titleString;
    }

}

}
A: 

I don't know why setting alpha doesn't work for you, but you could set the alpha in the beginFill call:

backing1.graphics.beginFill(bgColor, 0.1);
macke
Tried that same results :( ok so I knew I wasn't going crazy... just posted the full code
Leon
+1  A: 

I tried your source code, and the problem seems to be caused by the backing2-Shape. That sprite doesn't get any alpha, and is put ABOVE the backing 1, therefore apearing not to be transparent. When you delete the

addChild(backing2);

You will see the alpha.

Pbirkoff
Ah thx! That was it :) /facepalm
Leon
I'm glad it works :)
Pbirkoff