Hi;

I just uploaded a swf and, while it didn't throw an error, it didn't
display, either. There's one image that's rendered as a bitmap, but that
image is also there and in the appropriate folder. Why doesn't it render?

Also, I would prefer to embed this element in a standard HTML (or,
code-rendered pythonic version of the same) as opposed to re-creating this
site in Flash. My question is, since I have one element zoom in from full
screen to its final small size, I'm wondering if it's even possible. That
is, the embedded element would not be the entire screen, yet that's how the
Flash movie would begin.

Please advise on both counts.
TIA,
beno

package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.DisplacementMapFilter;
import flash.filters.GlowFilter;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.utils.Timer;
import com.greensock.*;
import com.greensock.easing.*;
 public class SpinningWorld extends Sprite
{
// The Bitmap containing the Earth map that's actually displayed on the
screen.
private var sphere:Bitmap;
 // The Earth map "source" -- pixels from this map are copied onto sphere
// to create the animated motion of the Earth.
private var textureMap:BitmapData;
 // The radius of the Earth.
private var radius:int;
 // The current x position on textureMap from which the pixels are copied
onto sphere.
private var sourceX:int = 0;
 // EarthSphere constructor
// Starts loading the Earth image.
public function SpinningWorld()
{
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
imageLoadComplete);
imageLoader.load(new URLRequest("images/world_map_doubled-small.png"));
}
 // Movement (a'la rotation) routine
private function rotateEarth(event:TimerEvent):void
{
sourceX += 1;
if (sourceX >= textureMap.width / 2)
{
sourceX = 0;
}
 sphere.bitmapData.copyPixels(textureMap,
  new Rectangle(sourceX, 0, sphere.width, sphere.height),
  new Point(0, 0));
 event.updateAfterEvent();
}
 // Creates the displacement map image that's used to create the fisheye
lens effect
private function createFisheyeMap(radius:int):BitmapData
{
var diameter:int = 2 * radius;
 var result:BitmapData = new BitmapData(diameter,
diameter,
false,
0x808080);
 // Loop through the pixels in the image one by one
for (var i:int = 0; i < diameter; i++)
{
for (var j:int = 0; j < diameter; j++)
{
// Calculate the x and y distances of this pixel from
// the center of the circle (as a percentage of the radius).
var pctX:Number = (i - radius) / radius;
var pctY:Number = (j - radius) / radius;
 // Calculate the linear distance of this pixel from
// the center of the circle (as a percentage of the radius).
var pctDistance:Number = Math.sqrt(pctX * pctX + pctY * pctY);
 // If the current pixel is inside the circle,
// set its color.
if (pctDistance < 1)
{
// Calculate the appropriate color depending on the
// distance of this pixel from the center of the circle.
var red:int;
var green:int;
var blue:int;
var rgb:uint;
red = 128 * (1 + 0.75 * pctX * pctX * pctX / (1 - pctY * pctY));
green = 0;
blue = 0;
rgb = (red << 16 | green << 8 | blue);
// Set the pixel to the calculated color.
result.setPixel(i, j, rgb);
}
}
}
return result;
}
 // Called when the Earth map image finishes loading.
// Sets up the on-screen elements (Earth image with fisheye filter and its
mask);
// starts the Timer that creates the animation effect.
private function imageLoadComplete(event:Event):void
{
textureMap = event.target.content.bitmapData;
radius = textureMap.height / 2;
 sphere = new Bitmap();
sphere.bitmapData = new BitmapData(textureMap.width / 2, textureMap.height);
sphere.bitmapData.copyPixels(textureMap,
  new Rectangle(0, 0, sphere.width, sphere.height),
  new Point(0, 0));

// Create the BitmapData instance that's used as the displacement map image
// to create the fisheye lens effect.
var fisheyeLens:BitmapData = createFisheyeMap(radius);
 // Create the fisheye filter
var displaceFilter:DisplacementMapFilter;
displaceFilter = new DisplacementMapFilter(fisheyeLens,
 new Point(radius, 0),
 BitmapDataChannel.RED,
 BitmapDataChannel.BLUE,
 radius, 0);
 // Apply the filter
sphere.filters = [displaceFilter];

this.addChild(sphere);
 // Create and apply the image mask
var EarthMask:Shape = new Shape();
EarthMask.graphics.beginFill(0);
EarthMask.graphics.drawCircle(radius * 2, radius, radius);
this.addChild(EarthMask);
this.mask = EarthMask;
 // Set up the timer to start the animation that 'spins' the Earth
var rotationTimer:Timer = new Timer(15);
rotationTimer.addEventListener(TimerEvent.TIMER, rotateEarth);
rotationTimer.start();
 // add a slight atmospheric glow effect
this.filters = [new GlowFilter(0xC2C2C2, .75, 20, 20, 2,
BitmapFilterQuality.HIGH, true)];
 dispatchEvent(event);
}
}
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to