日期:2014-05-16  浏览次数:20361 次

javascript已经声明了一个变量而且已经检验获取到值了,为什么在火狐上一运行显示该变量未定义呢
急求答案,真的要急死了。
var canvas = document.getElementById("mycanvas");
  var ctx = canvas.getContext("2d");
  var canvasData = ctx.createImageData(canvas.width, canvas.height);// Mandelbrot
 
var colors = [
new Color(0, 0, 0),
new Color(63, 63, 63),
new Color(127, 127, 127),
new Color(191, 191, 191),
new Color(255, 255, 255)];
var cg =new ColorGradient(minSa,maxSa,colors);
<!--var cg = new ColorGradient();
//cg = GreyScale(minSa,maxSa);
//alert(cg._min)-->  
 
var Width = maxX - minX;
var Height = maxY - minY;
 
for(var i = 0;i<myPsPoints.length;i++)
{
//var pointcolor = new Color(0,0,0);
var pointcolor = cg.GetColor(parseFloat(myPsPoints[i].amplitude));
var X = myPsPoints[i].x;
var Y = myPsPoints[i].y;  
var x = parseInt(canvas.width - canvas.width*(X-parseInt(minX))/Width);
var y = parseInt(canvas.height*(Y-parseInt(minY))/Height);
  //var color = 198;
  // Index of the pixel in the array
  var idx = (x + y * canvas.width) * 4;
 
//var c = new Color(250,0,0);
//alert(c.r);
 
  // Update the values of the pixel;
  canvasData.data[idx + 0] = pointcolor.r;
  canvasData.data[idx + 1] = pointcolor.g;
  canvasData.data[idx + 2] = pointcolor.b;
  canvasData.data[idx + 3] = 255;
  }
  ctx.putImageData(canvasData, 0,0);
这部分是我写在html5文件里面的js代码,这里面的pointcolor我已经在一开始声明并初始化好了。。在火狐里面用alert检验的时候可以正常传递到值(即pointcolor是有内容的),但是一去掉alert,运行时firebug显示pointcolor is undefined

------解决方案--------------------
哦 你函数里有用到settimeout 或者ajax异步之类的吧

这样的话 是会有问题
------解决方案--------------------
权限问题吧,记得canvas中好像不允许访问颜色的值的(出于安全考虑)!