Copy link to clipboard
Copied
Ok I'm having a lot of trouble with ActionScript 3. I'm supposed to make five buttons that when clicked show a different blend mode using 2 or more shapes. Each of these blend modes also has to have a text box explaining what the blend mode does. The assignment requires only one layer which is the actions layer. Everything has to be made using script only, which is why I'm having so many problems.
Can someone please help me with this and simplify it has much as possible. I need to have some sort of answer sometime tomorrow. I thank anyone who helps.
I have this code so far.
import flash.text.TextField;
import flash.text.TextFormat;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.display.Shape;
//create button instances
var btn:darkBtn = new darkBtn;
var btn2:invertBtn = new invertBtn;
var btn3:overBtn = new overBtn;
var btn4:screenBtn = new screenBtn;
var btn5:subBtn = new subBtn;
//add our interface objects to the main display list
addChild(btn);
addChild(btn2);
addChild(btn3);
addChild(btn4);
addChild(btn5);
//button positions
btn.x = 12;
btn.y = 395;
btn2.x = 131;
btn2.y = 395;
btn3.x = 250;
btn3.y = 395;
btn4.x = 367;
btn4.y = 395;
btn5.x = 485;
btn5.y = 395;
//create a new font
var mainFont = new GeorgiaRegular();
//create a new text format object
var mainFormat:TextFormat = new TextFormat();
mainFormat.size = 18;
mainFormat.leading = 4.5;
mainFormat.font = mainFont.fontName;
mainFormat.kerning = true;
//create text field copy
var mainTxt:TextField = new TextField;
mainTxt.x = 307;
mainTxt.y = 182;
mainTxt.width = 221;
mainTxt.height = 333;
mainTxt.multiline = true;
mainTxt.wordWrap = true;
mainTxt.defaultTextFormat = mainFormat;
mainTxt.autoSize = TextFieldAutoSize.LEFT;
mainTxt.embedFonts = true;
//create a URLLoader object
var textLoad:URLLoader = new URLLoader;
//create a new URLRequest
var darkReq:URLRequest = new URLRequest ("text/dark.txt");
var invertReq:URLRequest = new URLRequest ("text/invert.txt");
var overReq:URLRequest = new URLRequest ("text/over.txt");
var screenReq:URLRequest = new URLRequest ("text/screen.txt");
var subReq:URLRequest = new URLRequest ("text/sub.txt");
//test to see that the external file has completely loaded
//once it has executed the function that will add the loaded content
//to our dynamic text field
textLoad.addEventListener(Event.COMPLETE, textComplete);
//function to execute once the external data is loaded;
//adds the external file data (the actual text) to our text field
function textComplete(event:Event):void
{
mainTxt.text = event.target.data;
}
//create a new shape object
var sq:Shape = new Shape();
//use the lineStyle method of the graphics object to
//set the line thickness and color
sq.graphics.lineStyle(2, 0x000000);
//use the beginFill method to fill the shape
//with the specified color
sq.graphics.beginFill(0xFF86600);
//use the drawRect method to draw a rectangle
sq.graphics.drawRect(175, 100, 100, 100);
//use the endFill method to end the fill of the shape
sq.graphics.endFill();
//add our shaped to the display list
addChild(sq);
//create a new shape object
var circ:Shape = new Shape();
//use the lineStyle method of the graphics object to
//set the line thickness adn color
circ.graphics.lineStyle(2, 0x000000);
//use the beginFill method to fill the shape
//with the specified color
circ.graphics.beginFill(0xFF9900);
//use the drawCircle method to draw a circle
circ.graphics.drawCircle(150, 150, 85);
//use the endFill method to end the fill of the shape
circ.graphics.endFill();
//add our shape to the display list
addChild(circ);
//apply a blend mode to the circle
circ.blendMode = BlendMode.MULTIPLY;
//create a display object container
var contentContainer:Sprite = new Sprite;
addChild(contentContainer);
contentContainer.x = 10;
contentContainer.y = 24;
contentContainer.width = 1000;
contentContainer.height = 725;
//set initial page
contentContainer.addChild(mainTxt);
textLoad.load(darkReq);
Copy link to clipboard
Copied
blendModes can only be applied to DisplayObjects (Sprites, MovieClips, Bitmaps etc)
For an example how to get it working:
Copy link to clipboard
Copied
Oh gawd thank you, this is exactly what I was looking for!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now