BeginGradientFill Not Working As Expected
I'm sure it's my fault - considering I know infentecimally little about the matrix in flash...but...here goes...My problem is such that I want to create an inner shadow in a movieclip. Basically I want to re-create the shape tweening photo gallery look. So far I've only gotten to the point where I've created a white rectangle mc using the beginFill, lineTo so on and so forth....Now I'm trying to create an inner shadow using the beginGradientFill method.Now what's happening is that I just get a grey box...no gradient; I've duplicated the code used to create it, and if I'm not in the photo_paper mc, it works just fine...can anyone help?Just put this code on the main timeline and you'll see what I mean.Code: import flash.geom.Matrix;//// Functions ----------------------------------------------MovieClip.prototype.drawPaper = function():Void { // variables var w:Number = this.theWidth; var h:Number = this.theHeight; var l:Number = -(w/2); var r:Number = w/2; var t:Number = -(h/2); var b:Number = h/2; var fillType:String = "linear"; var colors:Array = [0x999999, 0x999999]; var alphas:Array = [100, 0]; var ratios:Array = [0, 0xFF]; var myMatrix:Matrix = new Matrix(); myMatrix.createGradientBox(10, h); // draw paper this.moveTo(l, t); this.beginFill(0xFFFFFF, 100); this.lineStyle(0, 0xFFFFFF, 0, false, "none", "none", "miter", 1); this.lineTo(r, t); this.lineTo(r, b); this.lineTo(l, b); this.lineTo(l, t); this.endFill(); // draw the paper inner shadow var leftS:Object = this.createEmptyMovieClip("leftShadow", this.getNextHighestDepth()); leftS.moveTo(l, t); leftS.beginGradientFill(fillType, colors, alphas, ratios, myMatrix); leftS.lineStyle(0, 0xFFFFFF, 0, false, "none", "none", "miter", 1); leftS.lineTo(l+10, t); leftS.lineTo(l+10, b); leftS.lineTo(l, b); leftS.lineTo(l, t); leftS.endFill();};// ---------------------------------------------------------////// Create photo_paper mc -----------------------------------var mc:Object = this.createEmptyMovieClip("photo_paper", this.getNextHighestDepth());mc.theWidth = 300;mc.theHeight = 500;mc._x = Stage.width/2;mc._y = Stage.height/2;mc.drawPaper(Stage.width/2, Stage.height/2);// ---------------------------------------------------------//
Actionscript 2.0
Posted on: Sat Sep 30, 2006 3:21 pm
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
BeginGradientFill Not Working In V7 Player?
Hi
The code below is copied directly from the helpdocs - and when published as player version 6 it works fine - BUT when publishing as v7 it apparently does nothing... Does anyone know what is going on here?
Code:
_root.createEmptyMovieClip( "grad", 1 );
with ( _root.grad )
{
colors = [ 0xFF0000, 0x0000FF ];
alphas = [ 100, 100 ];
ratios = [ 0, 0xFF ];
matrix = { a:200, b:0, c:0, d:0, e:200, f:0, g:200, h:200, i:1 };
beginGradientFill( "linear", colors, alphas, ratios, matrix );
moveto(100,100);
lineto(100,300);
lineto(300,300);
lineto(300,100);
lineto(100,100);
endFill();
}
cheers
idi
IF Statement Not Working As Expected
Code:
for (i=0;i<12;i++){
if ( string1[i].MC._rotation==0 && ( _global.shootInstance != _root["sphere1"+i].sphereInstance ) ){
trace( _root["sphere1"+i].sphereInstance );
trace( _global.shootInstance );
trace( "different" );
}
The array string1 has 12 entries with each a different _rotation value. One of them is always zero.
sphereInstance and shootInstance are integers which can either be 1, 2 or 3.
When (string1[i].MC._rotation==0)==true the if script ALWAYS executes no matter what the second parameter gives. Many times the traces reveal that the two values are equal.
When I change the != to == the script never executes
This certainly got me puzzled :S
GotoAndPlay() Not Working As Expected
Hi everyone. Has something changed with gotoAndPlay()?
I am getting unexpected results. I have a simple 2 frame swf with nothing on the stage.
Frame 1 reads:
trace(currentFrame);
and Frame 2 reads:
trace(currentFrame);
gotoAndPlay(2);
The expected results are:
1
2
2
2
(etc.)
However I am getting:
1
2
1
2
1
2
(etc.)
Why is gotoAndPlay(2) actually going to frame 1 and looping from there? Has something changed in AS3?
Thanks!
Button Not Working As I Expected :(
Got two problems for ya'll:
1. I have a button that looks like a flaming letter.. pretty .. so I added a fire sound fx to the 'over' frame inside the button. I want it to immeadetly stop playing the sound fx when I mouse off the button. I've tried shorting the sound FX and looping it.. But then it keeps looping when I roll off the button. and doesn't seem to ever stop. I have set it to play once. but it also continues to play after I've rolled off. I really just want it to loop untill I am not hovering any more. It would be especially nice if it also faded out when I moused off. But I'm ok to settle on just it shutting up all togher when I'm not on it. ??? help!
and..
2. I have another button. It's cute.. :) looks like those old film strips of negatives you would get back in the day when you would take your photos in to get developed. and I have it as a button.. nested in it is a movie clip that unrolls the film strip when you mouse over it. And then voila... there are pictures to choose from. When you mouse out.. the film strip rolls back up and goes away. That all works fine and dandy but the little pics inside the film strip are buttons which at this point are nested in a movie clip which is nested in a button. And when i mouse on the thumb nails at the bottom of this nested chain they do something funny. I don't have the file up so you can see it but i can email you it if you would like to see. but basicly the film strip rolls back up and goes away because it thinks i'm off of it and that is what is controlling the movie clip from playing and stoping. even though the buttons are in the movie clip it .. well its hard to explain. so i don't know.
................ok.. I just got it up on a geocites account that.. didn't take that long.. hurray..
its at: http://www.geocities.com/acistephanie/FILM.html
when you mouse over the thumb nails the film wants to roll back up.. any ideas.
thanks in advance.
Stephanie
acistephanie@hotmail.com
OnDisconnect Not Working As Expected On IE7
I have an application for a poker game which works perfectly in Firefox 1.5 and 2.0, however in IE7 (not too sure about IE6 thou) there is a serious problem. I shall explain..
User logs in. Opens a popup of the game which is just a php script which loads in the SWF. SWF successfully connects the the FCS 1.5 and sits around waiting for another player... however at any time if the person closes the window and any other IE7 windows are open the "onDisconnect" rule on the server side does not execute, therefore since this game only allows you to play one game at any one time, if you try to open a window to start a new game it finds an existing instance of the player.
Only if *all* IE7 windows are closed does the onDisconnect finally recognise that the person has disconnected.
This is only happening in IE, wherehas FIrefox, Safari and Konq. all work as expected.
The browser flash plugin is version 9 on all the machines.
Anyone had or experience similar problems with the onDisconnect, and more importantly.. is there a fix? This is really urgent since this game should have gone out a while ago, and really just this problem is causing a hold-up.
If it helps, please check out the problem on PokerWars, login, open a game, close the popup window and re-open a new game... this is driving me *nuts*
Many thanks
Edited: 11/30/2006 at 12:07:16 AM by Wyldie
SetInterval Not Working As Expected
I used setInterval to fade the main sequence of my page. It works, but for some reason no matter what I change setInterval to, it does it at the same speed of 30 frames per second. So if it has to set the Alpha level from 100% to 0% it will take 3.3 seconds. You can see it here: Http://www.dhicompany.com. Does anyone know why this is or how to fix it?
Quote:
stop();
function fadeOut(){
_root.loaderClip._alpha--;
_root.barLoad1._alpha--;
_root.barLoad2._alpha--;
updateAfterEvent();
if(_root.barLoad2._alpha<=0){
clearInterval(timer);
_root.gotoAndPlay("startTwo");
}
}
timer = setInterval(fadeOut,10);
MouseEnabled Not Working As Expected
Hello. I have a MovieClip on the stage that's operating as a button with ROLL_OVER, ROLL_OUT, and CLICK events established. In the CLICK event, I want to disable the button through: theMovie.mouseEnabled = false, but it's not working! The ROLL_OVER, ROLL_OUT and CLICK events continue to fire despite trace statements confirming that mouseEnabled = false! Here's the code:
private function clickHandler(evt:MouseEvent):void {
//do some stuff...
var selectedClip:MovieClip = MovieClip(evt.currentTarget);
selectedClip.mouseEnabled = false; //mouse events are still enabled after this runs!
selectedClip.buttonMode = false; //this works
}
private function rollOverHandler(evt:MouseEvent):void {
//now that mouseEnabled = false, this event shouldn't fire, but it does!
//what's worse - the trace below confirms that mouseEnabled = false! shenannigans!
trace("this shouldn't be displayed at all", evt.currentTarget.mouseEnabled);
}
If anyone has any insight as to what's happening here, I would be grateful for your help! Thanks!
Andy
My Event Handler Not Working As Expected
Using Flash 8 Pro.
I have, I think, an event handler that runs every time this call is made
Code:
send.sendAndLoad("http://127.0.0.1/chat/login.php", receive, "POST");
It looks like this:
Code:
receive.onLoad = function()
{
trace ("Enter onLoad Handler");
if (this.stat == 1)
{
stat = this.stat;
netstatus = "Online";
gotoAndPlay(4)
}
if (this.curCon) //new file created
{
theStat=this.curCon; //if this number returned store it
trace("Returned Value: " +this.curCon);
}
}
I expect it to work like this. Every time I send some data to a php page this even handle is called. Only if the values in the if statements was set would that section of cade run.. However, I am finding the the second section runs every time even though the curCon value was never set my calling my php page..
Why is it that parts of the code are running even when the value has not been returned or a sendAndLoad command sent..
Paste In Place Not Working As Expected
I'm using flash 8 in slide presentation mode.
WHen I cut text from slide#1 and paste-in-place on slide #2, the position is visually off by a small amount.
The info panel shows them being off by a LOT. For example, the position of the upper left corner of the text on slide#1 is (-146.3,-19.4).
The position of the upper left corner of the thext on slide#2 is (-242.4,-220.1).
However, visually the appear to off by only a smidge.
WHat is going on?
ReadObject/writeObject Not Working As Expected.
Ok, so I'm trying to get serialization to work, and here is some test code which is not doing what I want it to do:
first I have a test class called TestClass and that code looks like this:
ActionScript Code:
package
{
import flash.utils.*;
public class TestClass
{
private var m_dict:Dictionary = new Dictionary();
public function get Dict():Dictionary
{
return m_dict;
}
}
}
then I have this code that attempts to serialize it:
ActionScript Code:
registerClassAlias("flash.utils.Dictionary", flash.utils.Dictionary);
registerClassAlias("TestClass", TestClass);
var test = new TestClass();
test.Dict["rah"] = 100;
var testArray:ByteArray = new ByteArray();
testArray.writeObject( test );
testArray.position = 0;
var test2:Object = testArray.readObject();
If I then browse through test2 the contents of test2's dictionary have not been copied. I'm not sure if this is a problem with the reading or the writing stage.
Any ideas?
Time Function Not Working As Expected. . .
Hello all,
I've been working on this project for months and I'm finally coming near the end and things are getting a little tougher.
I am wonder if anyone could help me on solving my time function problem.
The old way I have it at a standard 5 seconds, but when I try to read in the xml file put in an array and make it display according to the endtime, it outputs NaN, when I trace the sec.
ex. If endtime is 6 I need it to display for 6 second, then read the next endtime. The next endtime is 3, display for 3 seconds, and so on.
If I'm not making sense I will post a .fla file.
Code:
load_xml = new XML();
load_xml.ignoreWhite = true;
load_xml.onLoad = function(success) {
if (success) {
process(load_xml);
} else {
trace("Something is wrong, we're not opening!");
}
};
//Load up the XML file into Flash
load_xml.load('xmlFade/images2.xml');
//---Function that will be called when xml loads succesfully
//xmlDoc_xml is now a reference to the XML object where our information is stored
//item_arr = new Array("img", "startdate", "enddate", "url");
var cnt = 0; // jbum - counter for fades
var outputAry = new Array(); // jbum
var timerAry = new Array();
var tcnt = 0;
function process(xmlDoc_xml) {
var count = 0; // jbum counter for loading array
var tmrCnt = 0;
for (var n = 0; n<xmlDoc_xml.firstChild.childNodes.length; n++) {
if (xmlDoc_xml.firstChild.childNodes[n].nodeName == "promo") {
var str = xmlDoc_xml.firstChild.childNodes[n].childNodes[0].firstChild;
_global.timer=xmlDoc_xml.firstChild.childNodes[n].childNodes[1].firstChild;
trace(" output ["+count+"] = "+str);
outputAry[count++] = str; // store in array
trace(" Timer ["+tmrCnt+"] = "+timer);
timerAry[tmrCnt++] = timer; // store time in array
}
//This is where the loop ends
}
mc.fade(0, 7);
}
MovieClip.prototype.fade = function(endAlpha, speed) {
trace("called fade");
if (outputAry[cnt] == undefined) {
stop();
myInterval = setInterval(stopFade, time());
} else {
output = outputAry[cnt];
cnt = cnt+1;
}
if (this._alpha>endAlpha) {
speed *= -1;
}
this.onEnterFrame = function() {
if (Math.abs(endAlpha-this._alpha)>Math.abs(speed)) {
this._alpha += speed;
} else {
this.onEnterFrame = undefined;
myInterval = setInterval(beginFadeOut, time(sec));
this._alpha = endAlpha;
}
};
};
MovieClip.prototype.fadeIn = function(begalpha, speed) {
trace("called fadeIn");
this._alpha = 0;
if (this._alpha<begalpha) {
speed *= -1;
}
this.onEnterFrame = function() {
if (Math.abs(begalpha-this._alpha)>Math.abs(speed)) {
this._alpha -= speed;
} else {
process();
this._alpha = begalpha;
}
};
};
function beginFadeOut() {
clearInterval(myInterval);
mc.fadeIn(100, 7);
}
function time(sec) {
sec = ((timerAry[tcnt])*1000); //I need this one to work according to the xml file.
tcnt = tcnt+1;
//sec = ((10/2)*1000); //this is the old seconds holder.
trace("seconds called");
trace("here sec is "+sec);
return sec;
}
function stopFade() {
clearInterval(myInterval);
}
Here is my xml file:
<?xml version="1.0" encoding="iso-8859-1"?>
<images>
<promo>
<img>promo1.jpg</img>
<endtime>6</endtime>
<url>website</url>
</promo>
<promo>
<img>promo2.jpg</img>
<endtime>3</endtime>
<url>website</url>
</promo>
<promo>
<img>promo3.jpg</img>
<endtime>1</endtime>
<url>website</url>
</promo>
</images>
If anyone could help me with this particular function it would be greatly appreciated!
Thanks,
cbs
GetVarialbe(); SetVariable(); Not Working As Expected?
Hello, I'm trying to understand how GetVariable() and SetVariable() work.
I've written the following ActionScript code in the actions frame of the top layer in my .fla:
testVar = "test1";
getVar = GetVariable("testVar");
SetVariable("testVar", "test2");
getVar2 = GetVariable("testVar");
When I walk through this code in the debugger, I don't see the expected behavior:
getVar - remains undefined
testVar - does not get assigned "test2" like I thought it would by calling SetVariable()
getVar2 - remains undefined.
I'm guessing it has something to do with variable scoping or something like that, but I'm not sure what.
Any help?
Thanks in advance.
MovieClip._visible Not Working As Expected [Flash Pro 8]
I have some AS that creates a movie clip and later tries to make it go away. However, _visible isn't working as I would think. Here's a sample:
I create the triangle:
Code:
triangle30 = createEmptyMovieClip("triangle30", this.getNextHighestDepth());
with(triangle30) {
lineStyle(1, 0xff0000, 100);
moveTo(0,0);
lineTo(10,10);
lineTo(0,10);
lineTo(0,0);
and then later try to make it go away:
Code:
triangle30._visible = false;
It doesn't work, however. So, I tried trace(triangle30._visible) both before and after the second chunk of code, and it does indeed change from true to false. However, the movie clip is still visible on the screen. Any idea what's going on?
-Mathminded
[flash8] For Loop SlideTo Is Not Working As Expected
In the following code, I create 12 buttons, label them, and control their onRollOver, onRollOut, and onRelease actions. Everything is working fine except for the line containing the "slideTo" method. Reading from the two arrays for the x and y values, it appears to be inserting the largest number in each array instead of stepping through all 12 values. Currently, clicking on any of the buttons moves the object (ralphMC) to x=100 and y=800. I am pretty stumped about this, as I've inserted quite a few various numbers into each array during testing. Can anyone tell me what I am doing wrong?
slideTo is part of the mcTween package, in case anyone wanted to know. code follows:
ActionScript Code:
//Creates an array of numbers that will evenly space the buttons out verticallyvar mcPosY:Array = new Array();for(var i = 0; i < 14; i++){ mcPosY[i] = i * 16;}//Creates button labels and the x and y positions of each of 12 cells in the searchAreaContent movieclipbtnLabels = ["Name/Keyword", "Type", "Race/Class", "Professions/Talent", "Faction/Flavor", "Allowed", "Cost/Card No.", "Rules", "Attack", "Health/Defense", "Rarity", "Artist/Set Name"];btnX = [100, -200, -300, -400, -500, -600, -700, 100, -1000, 100, 100, 100];btnY = [-100, -600, -200, -100, -100, -800, -100, -300, -100, -400, -100, -800];for(var i = 0; i < btnLabels.length; i++){ var myBtn = attachMovie("sambHolder", "gertrude_"+i, i); var Xpos = btnX[i]; var Ypos = btnY[i]; this.myBtn.sambBtn.dyTxt.text = btnLabels[i]; this.myBtn._x = 4; this.myBtn._y = mcPosY[i]; this.myBtn.onRollOver = function():Void{ this.gotoAndStop(2); } this.myBtn.onRollOut = function():Void{ this.gotoAndStop(1); } this.myBtn.onRelease = function():Void{ _root.searchPanelMC.sacHolderMC.ralphMC.slideTo(Xpos, Ypos, 2, "easeInOutQuad"); trace("x pos= " + _root.searchPanelMC.sacHolderMC.ralphMC._x) trace("y pos= " + _root.searchPanelMC.sacHolderMC.ralphMC._y) }}
BeginGradientFill Bug?
I'm using beginGradientFill to fake a hatched pattern fill at run-time. However, I've noticed that if you add more than about 8 color points in your gradient, everything beyond that gets ignored. Is there a way to get the drawing api gradient fill to draw fills with hundreds of color points, or do I have to do a fresh fill for every two lines in my hatch?
BeginGradientFill()
Ok I am trying to use beginGradientFill() but can't get the hang of it.
All examples I have searched for with google have just copied and pasted the MX help file. And while I haven't given up on working it out I am hoping someone might have some similar code or link to an example.
This is almost what I am after.... It allows you to play with the gradients using sliders. I just want to have a few pre-set colors to click on, no sliders.
http://www.horstkgrafix.de/smax/gradient.html
Here is a picture to explain basicly what I am trying to do.
Any code, links to examples, and it need not be the exact thing I am after, just something to work off is much appreciated.
BeginGradientFill() ?
Code:
import flash.geom.*
import flash.display.*
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xFF0000, 0x0000FF];
var alphas:Array = [100, 100];
var ratios:Array = [0x00, 0xFF];
var matr:Matrix = new Matrix();
matr.createGradientBox(20, 20, 0, 0, 0);
var spreadMethod:String = SpreadMethod.PAD;
up.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
up.graphics.drawRect(410,115,10,10);
up.graphics.endFill ();
all Im after is a gradient that is white on the bottom horizontal and gradually gets to black at the top, this above, taken from Flash's help is confusing the hell out of me. can anyone help? i dont know how to make it...
thanks
dai2
BeginGradientFill()
Ok I am trying to use beginGradientFill() but can't get the hang of it.
All examples I have searched for with google have just copied and pasted the MX help file. And while I haven't given up on working it out I am hoping someone might have some similar code or link to an example.
This is almost what I am after.... It allows you to play with the gradients using sliders. I just want to have a few pre-set colors to click on, no sliders.
http://www.horstkgrafix.de/smax/gradient.html
Here is a picture to explain basicly what I am trying to do.
Any code, links to examples, and it need not be the exact thing I am after, just something to work off is much appreciated.
BeginGradientFill Bug
I have an application that draws shapes based on some xml input. The color values are dynamically passed in as strings. I escape the values and store them for use when drawing each shape on the screen. basic fills work fine with the stored values however gradient fills won't read the stored values the same. Has anyone seen this before?
var DominantColor;
var PassiveColor;
function DrawTopSection() {
var y_Start = OverAllStartY-TopLine_Height;
var y_Adjust = y_Start+TopSection_Height;
this.createEmptyMovieClip("mc_Top", this.getNextHighestDepth());
colors = [DominantColor, PassiveColor];
alphas = [50, 100];
ratios = [0, 255];
radians = 0;
matrix = {matrixType:"box", x:50, y:50, w:OverAllWidth-75, h:OverAllWidth-75, r:radians};
mc_Top.beginGradientFill("linear", colors, alphas, ratios, matrix);
mc_Top.moveTo(0, 467);
mc_Top.lineTo(OverAllWidth, 467);
mc_Top.lineTo(OverAllWidth, 471);
mc_Top.lineTo(0, 471);
mc_Top.lineTo(0, 467);
mc_Top.endFill();
}
function ParseSlideData() {
var StartNode = Slides_Xml.firstChild;
DominantColor = escape(XPathAPI.selectSingleNode(StartNode, "slides/slide/dominantcolor").firstChild.nodeValue);
PassiveColor = escape(XPathAPI.selectSingleNode(StartNode, "slides/slide/passivecolor").firstChild.nodeValue);
}
MX - Dont Quite Get The Help On BeginGradientFill
Hi,
I understand most of the help on beginGradientFill.
matrix is what is still a bit fuzzy.
What does this from the flash help mean?
matrix A transformation matrix that is an object with either of the following two sets of properties.
this version makes sense to me....
matrix = { matrixType:"box", x:100, y:100, w:200, h:200, r45/180)*Math.PI };
but this one confuses....
a, b, c, d, e, f, g, h, i, which can be used to describe a 3 x 3 matrix of the following form:
a b c
d e f
g h i
this is the code from the example
matrix = { a:200, b:0, c:0, d:0, e:200, f:0, g:200, h:200, i:1 };
I messed with the values but it did not reveal itself to me ;-)
thanks for any help
mark
How To Set A Matrix With BeginGradientFill
Hi, I am trying to recreate the attached radial gradient fill with code.
I am a little hungover and tired, but I really want to work it out before calling it a day.
In the manual is say use the following, with matrix defining the shape of the gradient.
colors = [ 0x000000, 0xFFFFFF ];
alphas = [ 35, 35 ];
ratios = [ 0xFF, 0xFF ];
matrix = { a:0, b:10, c:20, d:10, e:10, f:20, g:20, h:20, i:1 };
this.beginGradientFill( "radial", colors, alphas, ratios, matrix );
Any enlightenment or example would be really great...
M@)
BeginGradientFill Using Three Colors. Is It Possible?
Is it possible to create a gradient that has more than two colors, i.e.: red to yellow to green? I am using the following code and using only two colors. But I want to use three colors.
Here is the code:
_root.createEmptyMovieClip( "grad", 1 );
with ( _root.grad )
{
colors = [ 0xFF0000, 0x00FF00 ];
alphas = [ 80, 100 ];
ratios = [ 0, 0xFF ];
matrix = { matrixType:"box", x:100, y:100, w:200, h:200, r90/180)*Math.PI };
beginGradientFill( "linear", colors, alphas, ratios, matrix );
moveTo(100,100);
lineTo(100,300);
lineTo(300,300);
lineTo(300,100);
lineTo(100,100);
endFill();
}
How To Use The BeginGradientFill Function?
Hello I am new to this forum and also new to programming in actionscript 3. Please pardon me if any of the questions I ask sound very noobiesh because it probably is.
I have a piece of code that attempts to apply a gradient affect onto a shape. the shape is an instance of a movie clip, which was created and saved onto a .swf file.
Inside my code, I grab this shape from the .swf file and pass this object into the function. The function then applies the gradient affect onto the shape object. Here is what my code looks like:
protected function convertToSkinColor(target:MovieClip, skinColor:String){
var fillType:String = GradientType.LINEAR;
var colors:Array;
var alphas:Array;
var ratios:Array;
var gradMatrix:Matrix;
var spreadMethod:String = SpreadMethod.PAD;
colors = [skinColor, 0x00ggdd, 0x00ggfe]
alphas = [100, 100, 100];
ratios = [204, 229, 247];
gradMatrix = new Matrix();
gradMatrix.createGradientBox(target.width, target.height, 0, 0, 0);
target.graphics.clear();
target.graphics.beginGradientFill(fillType, colors, alphas, ratios, gradMatrix, spreadMethod);
target.graphics.drawRect(0,0,target.width,target.h eight);
target.graphics.endFill();
}
target is the shape being passed into the function. When I run the code, the gradient is created but it is not being applied onto the shape. the whole gradient sits underneath the shape object.
So if I modified target.width and target.height to greater size than the shape's dimensions, I can see edges of the gradient comming off from the edges of the shape. Just picture a smaller circle sitting on top of a larger circle.
How do I get the gradient to be applied onto the shape? The shape has its own colors.
Problem With BeginGradientFill
I'm using the below screenshot to show my problem:
I'm drawing the above grid with 4 lines each time. Each time 4 lines are drawn I'm filling the tile with a gradient and move to the next tile. The problem is that the whole grid is filled with a continuous gradient instead of each tile getting it's own fill.
Anyone knows what might be the reasons for this or how I can fix this issue? Thanks for whoever answers!
BeginGradientFill Issue
Code:
package com
{
import flash.display.Sprite;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.geom.Matrix;
public class Window extends Sprite
{
private var p_cornerCurveAmt:int;
private var p_bg:Sprite;
public function Window(w:int, h:int)
{
p_cornerCurveAmt = 10;
p_bg = new Sprite();
p_bg.graphics.beginGradientFill(GradientType.LINEAR, [0x000000,0xffffff], [1,1], [0,255], new Matrix(), SpreadMethod.PAD);
p_bg.graphics.drawRoundRect(0,0,w,h,p_cornerCurveAmt,p_cornerCurveAmt);
p_bg.graphics.endFill();
addChild(p_bg);
}
}
}
for some reason this is only creating a light gray to a lighter gray.
even though i entered the colors black and white
what am i doing wrong here?
also, i want the gradient to be verticle... how do i set that?
Begingradientfill Question
How do I get the gradient fill to go from top to bottom instead of sideways?
-------------------
var FF2text:MovieClip = createEmptyMovieClip ("FF2text", getNextHighestDepth());
onEnterFrame = function(){
import flash.filters.GlowFilter;
var glowInstance:GlowFilter = new GlowFilter(0xFFFFFF, 0.6, 5, 5);
FF2text.filters = [glowInstance];
import flash.geom.Matrix;
var gradbox:Matrix = new Matrix();
gradbox.createGradientBox(200, 100);
FF2text.lineStyle (3,0xFFFFFF,95,true,none,none,square,0)
//FF2text.beginFill (0x2425DB);
FF2text.beginGradientFill("linear", [0x2425DB, 0x000000], [100, 100], [0x00, 0xFF], gradbox);
FF2text.moveTo (105, 100);
FF2text.lineTo (395, 100);
FF2text.curveTo(400, 100, 400, 105);
FF2text.lineTo (400, 195);
FF2text.curveTo(400, 200, 395, 200);
FF2text.lineTo (105, 200);
FF2text.curveTo(100, 200, 100, 195);
FF2text.lineTo (100, 105);
FF2text.curveTo(100, 100, 105, 100);
FF2text.endFill ();
}
--------------------
SpotlightEffect? BeginGradientFill
I cant get a spotlight effect with gradientfill to work right i
create an object that represents the gradient and then i tween it from small to huge... and draw a box the size of the screen and fill it and on each updateMovement I redraw the gradient with a alpha 0 center and a 255 edge...
but it doesnt center right at all...no matter what i do. anyone have any ideas or can make me an example gradient that grows and at the end just the corners are darker?
It always is off Center...(oh Im using Stage.width/height since it needs to be dynamically resized based on browser...)
Using The BeginGradientFill Function
Hello I am new to this forum and also new to programming in actionscript 3. Please pardon me if any of the questions I ask sound very noobiesh because it probably is.
I have a piece of code that attempts to apply a gradient affect onto a shape. the shape is an instance of a movie clip, which was created and saved onto a .swf file.
Inside my code, I grab this shape from the .swf file and pass this object into the function. The function then applies the gradient affect onto the shape object. Here is what my code looks like:
protected function convertToSkinColor(target:MovieClip, skinColor:String){
var fillType:String = GradientType.LINEAR;
var colors:Array;
var alphas:Array;
var ratios:Array;
var gradMatrix:Matrix;
var spreadMethod:String = SpreadMethod.PAD;
colors = [skinColor, 0x00ggdd, 0x00ggfe]
alphas = [100, 100, 100];
ratios = [204, 229, 247];
gradMatrix = new Matrix();
gradMatrix.createGradientBox(target.width, target.height, 0, 0, 0);
target.graphics.clear();
target.graphics.beginGradientFill(fillType, colors, alphas, ratios, gradMatrix, spreadMethod);
target.graphics.drawRect(0,0,target.width,target.h eight);
target.graphics.endFill();
}
target is the shape being passed into the function. When I run the code, the gradient is created but it is not being applied onto the shape. the whole gradient sits underneath the shape object.
So if I modified target.width and target.height to greater size than the shape's dimensions, I can see edges of the gradient comming off from the edges of the shape. Just picture a smaller circle sitting on top of a larger circle.
How do I get the gradient to be applied onto the shape? The shape has its own colors.
Does Anyone Know About The BeginGradientFill Command In MX
Hi,
I posted this on a couple of other forums, zero replies.
so are you guys better
in mx there is the actionscript command beginGradientFill.
it requires a "matrix"
there are two types
one is
matrixType:box, x, y, w, h, r.
which is fairly obvious a box at x,y so wide so high with rotation.
the other is used like this
matrix = { a:200, b:0, c:0, d:0, e:200, f:0, g:200, h:200, i:1 };
the help says based on a 3 x 3 matrix
abc
def
ghi
can anyone explain how this matrix works, the help is, well not much help!
thanks mark
How To Set A Matrix With BeginGradientFill
Hi, I am trying to recreate the attached radial gradient fill with code.
I am a little hungover and tired, but I really want to work it out before calling it a day.
In the manual is say use the following, with matrix defining the shape of the gradient.
colors = [ 0x000000, 0xFFFFFF ];
alphas = [ 35, 35 ];
ratios = [ 0xFF, 0xFF ];
matrix = { a:0, b:10, c:20, d:10, e:10, f:20, g:20, h:20, i:1 };
this.beginGradientFill( "radial", colors, alphas, ratios, matrix );
Any enlightenment or example would be really great...
http://www.3ainteractive.com/temp/fill.jpg
M@)
BeginGradientFill Question
Why does this return an error:
Code:
var oMatrix:Object = {matrixType: "box", x: 0, y: 0, w: 100, h: 100, 0};
mcClip.beginGradientFill("linear", aColors, aAlphas, aRatios, aMatrix);
Thanks in advance
Luis Guerreiro
Query Related To BeginGradientFill
hello,
beginGradientFile has 5 parameters
movieClip.beginGradientFill(fillType, colors, alphas, ratios, matrix);
I am having problems understanding the last parameter i.e. matrix;
Can someone explain me this line of code:
matrix = { matrixType:"box", x:100, y:100, w:200, h:200, r:radians }
PhotoShop CS3 Gradient To BeginGradientFill
Hi all,
I have been given a design for a button that uses a gradient overlay in Photoshop CS3. I want to translate it into the correct ratios / alphas for the beginGradientFill properties, is there an easy way to do this?
I have attached a picture to illustrate the grad.
Cheers
P.s. This is a snippet from my current class:
ActionScript Code:
package{
import flash.display.GradientType;
import flash.display.Sprite;
import flash.geom.Matrix;
import com.phase8.Button;
public class GuiButton extends Button{
/* ------------------------------------------------------------------------------
CONSTRUCTOR
------------------------------------------------------------------------------ */
public function GuiButton():void{
super(new Sprite());
this.params = {
colourOn: [0x403f3f,0x000000,0x403f3f,0x757575,0x999999,0x757575],
colourOff: [0x403f3f,0x000000,0x403f3f,0x757575,0x999999,0x757575],
colourOver: [0x403f3f,0x000000,0x403f3f,0x757575,0x999999,0x757575],
width: 90,
height: 30
};
}
/* ------------------------------------------------------------------------------
PUBLIC METHODS
------------------------------------------------------------------------------ */
override public function changeState(colour:Array):void{
var btnMatrix:Matrix = new Matrix();
btn.graphics.clear();
btn.graphics.lineStyle();
btnMatrix.createGradientBox(this.params.width,this.params.height, 270 /(180/Math.PI));
btn.graphics.beginGradientFill(GradientType.LINEAR,
colour,
[1,1,1,1,1,1],
[ 0,
colourPoint(.03),
colourPoint(.04),
colourPoint(.96),
colourPoint(.98),
1
],
btnMatrix);
btn.graphics.drawRoundRect(0,0,this.params.width,this.params.height,5);
btn.graphics.endFill();
}
/* ------------------------------------------------------------------------------
PRIVATE METHODS
------------------------------------------------------------------------------ */
}
}
BeginGradientFill Rotate Problem
I'm trying to rotate my gradient, but I can't get this work, I need some help.
Code:
import flash.geom.Matrix;
this.createEmptyMovieClip("mShape", 1);
mShape._x = 100;
mShape._y = 100;
var mxBox:Matrix = new Matrix();
drawRoundedRectangle(mShape, 240, 180, 10, 0x99FF00, 100);
function drawRoundedRectangle(target_mc:MovieClip, boxWidth:Number, boxHeight:Number, cornerRadius:Number, fillColor:Number, fillAlpha:Number):Void {
with (target_mc) {
moveTo(cornerRadius, 0);
mShape.lineStyle(2, 0, 100, false, "none", "none", "round");
mShape.beginGradientFill("linear", [0xFFFFFF, 0x1C232C, 0x232D38], [100, 100, 100], [0, 150, 200], mxBox, "reflect", "LinearRGB", 1);
//beginFill(fillColor, fillAlpha);
lineTo(boxWidth - cornerRadius, 0);
curveTo(boxWidth, 0, boxWidth, cornerRadius);
lineTo(boxWidth, cornerRadius);
lineTo(boxWidth, boxHeight - cornerRadius);
curveTo(boxWidth, boxHeight, boxWidth - cornerRadius, boxHeight);
lineTo(boxWidth - cornerRadius, boxHeight);
lineTo(cornerRadius, boxHeight);
curveTo(0, boxHeight, 0, boxHeight - cornerRadius);
lineTo(0, boxHeight - cornerRadius);
lineTo(0, cornerRadius);
curveTo(0, 0, cornerRadius, 0);
lineTo(cornerRadius, 0);
endFill();
}
}
Thanks
Depth Problem With BeginGradientFill
Hey,
I am creating a .swf with full screen and mainContent_mc centered. Thas is working just fine. Then i want to fill the background with beginGradientFill(); and using the createEmptyMovieClip(); then using lineTo(); and drawing out the box as big as the RESOLUTION. All that works fine now once i run the movie the mainContent_mc is behind the background i created using gradientFill. I have tried many depth things getHighestDepth(), getDepth(), swapDepth() and so on tried everything i can think of but it does not work. Any help would be appreciated.
Thank you in advance.
PS. the AS
ActionScript Code:
var valX = System.capabilities.screenResolutionX;
var valY = System.capabilities.screenResolutionY;
var strX:Number = valX;
var strY:Number = valY;
var aColors:Array = [0x333333, 0x00CC66, 0xCC3300];
var aAlphas:Array = [100, 30, 100];
var aRatios:Array = [0, 127.5, 255];
var oMatrix:Object = {matrixType:"box", x:10, y:50, w:strX, h:strY, r:Math.PI/2};
this.createEmptyMovieClip("mcBack", 1);
mcBack.beginGradientFill("linear", aColors, aAlphas, aRatios, oMatrix);
mcBack.lineTo(0, 0);
mcBack.lineTo(valX, 0);
mcBack.lineTo(valX, valY);
mcBack.lineTo(0, valY);
mcBack.endFill();
Stage.scaleMode = "noscale";
Stage.align = "tl";
Stage.addListener({onResize:reposition});
function reposition() {
var mcRep = _root.mainContent_mc;
var newX = Math.floor((Stage.width - mcRep._width) / 2);
mcRep._x = newX;
mcRep._y = 20;
_root.mainContent_mc.testLine._height = valY;
};
reposition();
BeginGradientFill Matrix Meaning
well the topic says all, I would like to know what does the matrix transformation parameters mean, since on the flashMx help itīs quite short itīs description.
thanks in advance
greetings,
Polaco
BeginGradientFill - PROBLEM WITH COLORS ARRAY
I got a HUGE problem with beginGradientFill function, as it says in the manual I pass it an array with bunch of color numbers (example "0x000000"). I let the user input these colors from the component properties window, so the array contains string variables (i assume) and i think thats where the problem lies! In the manual it shows u doing this:
colors = [0x000000,0xFFFFFF];
if you do this:
colors = ["0x000000","0xFFFFFF"];
ITS NOT GOING TO WORK. The question, how do i translate these text array elements into appropriate object type?
Please help
EXPERTS - BeginGradientFill With Brightness Factor?
hi guys
I want do draw a 10 gradients based on a begincolor and a brightness factor ... but how?
I have a variable containing a HEX value
how do I get a variable 'endColor' to represent a slightly brightened version of 'beginColor'?
Code:
gradientHeight = menu._height/2;
beginColor = "0x5B7CA7";
//endColor = ??????
gradientWidth = 200;
for(i=1;i<11;i++) {
with (_root.menu["level" + i]) {
colors = [ beginColor, endColor];
alphas = [ 100, 100 ];
ratios = [ 0, 255 ];
matrix = { matrixType:"box", x:0, y:-gradientHeight, w:gradientWidth, h:gradientHeight, r:(90/180)*Math.PI };
beginGradientFill( "linear", colors, alphas, ratios, matrix );
moveto(0,-gradientHeight);
lineto(gradientWidth,-gradientHeight);
lineto(gradientWidth,0);
lineto(0,0);
lineto(0,-gradientHeight);
endFill();
}
}
help me ...
Best regards
//POD
Why MovieClip.beginGradientFill() Help Example Doesn't Work ?
Hi, very very simple situation:
I've just copied and paste example code from FlashMX 2004 Help
to newly created file and tested the movie - BUT NOTHING HAPPENS AT ALL !!
example code (the simpliest one):
_root.createEmptyMovieClip( "grad", 1 );
with ( _root.grad )
{
colors = [ 0xFF0000, 0x0000FF ];
alphas = [ 100, 100 ];
ratios = [ 0, 0xFF ];
matrix = { a:200, b:0, c:0, d:0, e:200, f:0, g:200, h:200, i:1 };
beginGradientFill( "linear", colors, alphas, ratios, matrix );
moveto(100,100);
lineto(100,300);
lineto(300,300);
lineto(300,100);
lineto(100,100);
endFill();
}
when i try example code of MovieClip.beginFill() function everything goes fine and I can see the result.
code here:
_root.createEmptyMovieClip( "grad", 1 );
with (_root.grad){
beginFill (0xFF00FF, 100);
lineStyle (1, 0x000000, 100);
moveTo (0, 0);
lineTo (0, 20);
lineTo (50, 20);
lineTo (50, 0);
lineTo (0, 0);
endFill();
}
So - where the problem ? any ideas ?
I didn't modified anything - just copied and paste help example...
BeginGradientFill Color Array Confusion
I am a little lost!
I have created a class which draw a gradient and I am trying to dynamically set the colors of the gradient but when I swap the rgb values for variable names the gradient shows as black to white.
Here's my code:
Code:
public function drawGrad(colour2:Number, colour1:Number) {
_root.container_mc.createEmptyMovieClip("gradient_mc", 300);
with (_root.container_mc.gradient_mc) {
fillType = "linear";
var colors:Array = [colour2, colour1];
trace(colors);
alphas = [0, 100];
ratios = [127, 255];
matrix = {matrixType:"box", x:369, y:288, w:572, h:80, r:-45/180*Math.PI};
lineStyle(1, 0x000000, 0);
beginGradientFill(fillType, colors, alphas, ratios, matrix);
moveTo(369, 288);
lineTo(941, 288);
lineTo(941, 368);
lineTo(369, 368);
lineTo(369, 288);
endFill();
}
}
///call to action
var setGrad = new gradientFill();
setGrad.drawGrad(colour2, colour1);
Thanks in advance..
Dynamically Moving BeginGradientFill Shape
http://rwocreative.com/flaTests/grad01.fla
http://rwocreative.com/flaTests/grad01.swf
http://rwocreative.com/flaTests/grad01.html
I'm trying to create a dynamically-drawn box using the drawing API that utilizes beginGradientFill() (I'll call it bgf() from here on in) as the method to fill it with color. With bgf() I want to make it so that the "center" of the gradient follows the mouse's x/y position on-stage.
The problem I'm running into is that the "center" of the gradient doesn't follow the mouse's x/y coords correctly, it seems like it's exponentially increasing/decreasing it's position relative to the mouse's coords. Just look at the swf to see what I mean. Also, it seems that the gradient is also scaling relative to the top-left corner of the SWF, which it shouldn't be.
I *think* the problem lies in how I'm calculating the "center" of the gradient, but I've already busted my skull trying to see through the math. Anyone care to help me shed some light on the subject?
Thanks in advance.
BeginGradientFill Dynamic Color Array
I am using actionscript to create a gradient fill which works beautifully until I try to load the colour variables from an XML. The variables load successfully, when I trace the dynamic variables they show whats in the XML file (0xf6e3ba, 0xe9c98d) but the gradient appears white to black. When I use the HEX colour values in the code directly (the gradient works) but the trace returns (15321485, 16180154).
If I use these values in the XML file I still get white to black.
So what am I doing wrong?!
']' Expected?
I have the output window coming up with 2 errors saying,
**Error** Symbol=main_nav, layer=action, frame=1:Line 5: ']' expected
if (this["target" add i]<1)//OPTIMIZATION
what does this mean and how can I fix it?
Why Do I Get '{' Expected
Good Morning All. I am brand new to ActionScript so I KNOW this is a stupid question. I have been charged with creating flash banners for my boss. I have done one and added a URLRequest just fine. When I tried to add same script to next banner I keep getting a '{' expected error. I have worked on this for 2 hours now and simply cannot see any difference between the 2. Why would 1 work and the other not?
'(' Expected
I'm making a beat 'em up style game where you click a button and your character attacks..
heres my problem. on the button named 'punch' i want it so when you enter a certain frame on the 'ragebar' the enemy starts to go red.
i think i got the code right
on (release)
{_root.joe.gotoAndPlay(Punch);}
on {_root.ragebar.enterFrame('red1'); gotoAndPlay('gored');}
but it keeps saying '(' expected
and no matter what i do, it says the same thing OR says other things are wrong and the '(' expected again..
help would be greatly apprectiated.
Thanks.
';' Expected
can anyone tellme whats wrong with the script below I been tried
to figureit out but i don't see any problem ,:
on (press){
startDrag (this,true)
}
on (release){
stopDrag();
if (this._droptarget == "/2"){
_root.1S = 100;
}else{
_root.1S = 0;
}
}
';' Expected
Hello,
My project was going just fine, until suddenly i started to get this error everywhere: " ';' expected".
The strange thing is that the ";" is actually there.
One thing I did was to change instance names of some of the movie clips; then I wondered if that could have been the problem, so I started a new project from scratch, only to find that the ";" was still expected somewhere.
The following are the actions for one movie clip; for these lines I get errors in lines 3, 8, 9, 10, 14, and 15, always expecting a ";".
Code:
on (rollOver) {
gotoAndStop(2);
_root.01.gotoAndStop(2);
}
on (press) {
enabled = false;
_root.01.enabled = false;
_root.subquienes.1b.enabled = true;
_root.subquienes.1c.enabled = true;
}
on (release) {
_root.subquienes.1b.gotoAndStop(1);
_root.subquienes.1c.gotoAndStop(1);
}
on (rollOut) {
gotoAndStop(1);
}
As you can see, ";" is there. I am very disoriented about what steps to take. Does anyone have a clue on what could the error be?
Thanks,
Laura
')' Or ',' Expected -I'M STUMPED_
This works,
on (release) {tellTarget ("_level0.reciever")
{gotoAndStop(_level0.giver._currentframe);
}
}
But not this:
onClipEvent (load)
{tellTarget ("_level0.spinnerTop.110")
{gotoAndStop(_level0.faderTop.110._currentframe);
}
}
and I get this Output:
**Error** Scene=Scene 1, layer=Layer 5, frame=66:Line 4: ')' or ',' expected
{gotoAndStop(_level0.faderTop.110._currentframe);
**Error** Scene=Scene 1, layer=Layer 5, frame=66:Line 7: Unexpected '}' encountered
What's wrong with line 4?
What I am trying to do is pass _currentframe number from one MC to an identical one and stop there.
|