AS3 - Redirect to url after swf intro finishes
Mar 6, 2013 6:48 AM
Tags: none (add) #error #flash #as3 #3.0 #swf #action_script_3 #actionscript #intro #flash_professional #cs6 #flash_cs6I have a flash intro that i edited from a template, i have access to the fla and action script, i want the swf to auto redirect to my home page after the swf has finished rather than having to click the logo, i have tried using navigatetoURL with no luck.
EDIT : hope this makes sense as i have searched the forums and had no success with other solutions and i would greatly appreciate an answer ASAP
EDIT2: ALSO TRIED THE VIDEO EVENT AS SHOWN AT BOTTOM OF CODE - From another thread solution.
package
{
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.BulkProgressEvent;
import com.greensock.TimelineMax;
import com.greensock.TweenMax;
import com.greensock.easing.Elastic;
import com.greensock.easing.Linear;
import com.greensock.easing.Quad;
import com.greensock.easing.Sine;
import com.radykal.do3d.AnimatedLetter3D;
import com.radykal.do3d.Stripe3D;
import flash.net.*;
import flash.display.Bitmap;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Matrix;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import org.papervision3d.cameras.CameraType;
import org.papervision3d.core.clipping.FrustumClipping;
import org.papervision3d.core.culling.ViewportObjectFilter;
import org.papervision3d.core.culling.ViewportObjectFilterMode;
import org.papervision3d.core.effects.view.ReflectionView;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.layer.util.ViewportLayerSortMode;
public class StripeIntro3D extends ReflectionView
{
private var background:Sprite;
private var bulkLoader:BulkLoader;
private var preloader3D:AnimatedLetter3D;
private var xml:XML;
private var stripeColor:Number;
private var textColor:Number;
private var mySound:Sound;
private var logoBitmap:Bitmap;
private var logoCon:Plane;
private var orbitAdded:Boolean = false;
private var rot:Number= 0.3;
private var camPitch:Number = 90;
private var camYaw:Number = 270;
private var easeOut:Number = 0.1;
public function StripeIntro3D()
{
//setting the stage
stage.frameRate = 31;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.HIGH;
stage.addEventListener(Event.RESIZE, onResize);
//setting the 3d view
super(stage.stageWidth, stage.stageHeight, true, true, CameraType.FREE);
addBackground();
init3D();
loadAssets();
}
private function addBackground():void
{
//draw a gradient background
background = new Sprite();
var fType:String = GradientType.LINEAR;
var colors:Array = [0xFFFFFF, 0xFFFFFF];
var alphas:Array = [1, 1];
var ratios:Array = [150, 255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(stage.stageWidth, stage.stageHeight, Math.PI * 0.5, 0, 0 );
var sprMethod:String = SpreadMethod.PAD;
background.graphics.beginGradientFill( fType, colors, alphas, ratios, matrix, sprMethod );
background.graphics.drawRect(0, 0, width, height);
this.addChildAt(background, 0);
}
private function init3D():void
{
//3d settings
this.surfaceHeight = -220;
this.addDropOff(40, 255, 5);
this.viewport.autoCulling = true;
this.camera.z = -400;
this.camera.x =400;
this.camera.zoom = 25;
this.camera.focus = 10;
this.renderer.clipping = new FrustumClipping(FrustumClipping.NEAR);
this.viewport.containerSprite.sortMode = ViewportLayerSortMode.Z_SORT;
this.viewportReflection.viewportObjectFilter = new ViewportObjectFilter(ViewportObjectFilterMode.EXCLUSIVE);
//add a 3d preloader
preloader3D = new AnimatedLetter3D("1%");
preloader3D.rotationY = -45;
preloader3D.x = preloader3D.width * 2;
this.scene.addChild(preloader3D);
//add render
this.addEventListener(Event.ENTER_FRAME, render);
}
private function loadAssets():void
{
//loading all assets with bulkloader
bulkLoader = new BulkLoader("assets");
bulkLoader.add("xml/settings.xml", {id:"main"});
bulkLoader.add("images/logo.jpg", {id:"logo"});
bulkLoader.add("sound/mySound.wav", {id:"mySound"});
bulkLoader.addEventListener(BulkProgressEvent.PROGRESS, loadingAssets);
bulkLoader.addEventListener(BulkProgressEvent.COMPLETE, assetsLoaded);
bulkLoader.start();
}
private function loadingAssets(evt:BulkProgressEvent):void
{
//loading progress
var totalBytes:Number = evt.bytesTotal;
var loadedBytes:Number = evt.bytesLoaded;
var loaderProgress:Number = Math.ceil(loadedBytes / totalBytes * 100);
if(Number(loaderProgress) && loaderProgress != Infinity)
{
preloader3D.write = String(loaderProgress) + "%";
}
}
private function assetsLoaded(evt:BulkProgressEvent):void
{
this.scene.removeChild(preloader3D);
//getting the values from the xml file, the logo and the sound
xml = bulkLoader.getXML("main");
stripeColor = hexDecode(xml.colors.@stripe);
textColor = hexDecode(xml.colors.@text);
mySound = bulkLoader.getSound("mySound");
logoBitmap = bulkLoader.getContent("logo");
do3D();
}
private function do3D():void
{
//material for the logo plane
var logoMaterial:BitmapMaterial = new BitmapMaterial(logoBitmap.bitmapData, true);
logoMaterial.doubleSided = true;
logoMaterial.smooth = true;
logoMaterial.interactive = true;
//section one
var stripe1:Stripe3D = new Stripe3D(600, stripeColor);
stripe1.x = -400;
this.scene.addChild(stripe1);
var stripe2:Stripe3D = new Stripe3D(800, stripeColor);
stripe2.x = stripe1.x + stripe1.width;
stripe2.rotationY = 90;
this.scene.addChild(stripe2);
var text1:AnimatedLetter3D = new AnimatedLetter3D(xml.sections.one.text(), textColor); //min. 4 chars, max. 20 chars
text1.x = stripe2.x + 50;
text1.z = 800;
text1.scale = 2;
this.scene.addChild(text1);
//section two
var stripe3:Stripe3D = new Stripe3D(1500, stripeColor);
stripe3.x = 1366;
stripe3.z = 800;
stripe3.rotationY = 90;
this.scene.addChild(stripe3);
var text2:AnimatedLetter3D = new AnimatedLetter3D(xml.sections.two.text(), textColor); //min.5 chars, max.20 chars
text2.x = stripe3.x;
text2.z = stripe3.width + stripe3.z + text2.width * 2 + 50;
text2.rotationY = 90;
text2.scale = 2;
this.scene.addChild(text2);
var stripe4:Stripe3D = new Stripe3D(2000, stripeColor);
stripe4.x = text2.x;
stripe4.z = text2.z + 50;
stripe4.rotationY = 90;
this.scene.addChild(stripe4);
//section three
var stripe5:Stripe3D = new Stripe3D(8000, stripeColor);
stripe5.x = 600;
stripe5.z = text2.z - text2.width - 50;
stripe5.rotationX = 90;
stripe5.y = -100;
this.scene.addChild(stripe5);
var text3:AnimatedLetter3D = new AnimatedLetter3D(xml.sections.three.text(), textColor); //min.5 chars, max.20 chars
text3.x = stripe5.x + stripe5.width;
text3.z = stripe5.z - 100;
text3.rotationY = 90;
text3.localRotationZ = 180;
text3.scale = 2;
this.scene.addChild(text3);
//logo
logoCon = new Plane(logoMaterial, logoBitmap.width, logoBitmap.height);
logoCon.x = 7000;
logoCon.y = 100;
logoCon.z = text2.z - text2.width + 1000;
this.scene.addChild(logoCon);
//click handler for the logo
logoCon.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, openLink);
logoCon.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, overLogo);
logoCon.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, outLogo);
//timeline for section one
var sectionOne:TimelineMax = new TimelineMax({delay:1});
sectionOne.append(TweenMax.from(stripe1, 1, {scaleX:0, ease:Linear.easeNone, onStart:playSound}));
sectionOne.append(TweenMax.from(stripe2, 1, {scaleX:0, ease:Linear.easeOut}));
sectionOne.appendMultiple(TweenMax.allFrom(text1.letters3D, 2, {scale:3, rotationY:180, ease:Elastic.easeOut}, 0.05));
//timeline for section two
var sectionTwo:TimelineMax = new TimelineMax({delay:6.5});
sectionTwo.append(TweenMax.from(stripe3, 0.5, {scaleX:0, ease:Linear.easeNone}));
sectionTwo.appendMultiple(TweenMax.allFrom(text2.letters3D.reverse(), 1, {scale:0, y:300, ease:Sine.easeOut}, 0.05, remove3dObject, [[stripe1, stripe2, text1]]));
sectionTwo.append(TweenMax.from(stripe4, 1.5, {scaleX:0, ease:Linear.easeOut, onComplete:removeReflection, onCompleteParams:[text2]}));
sectionTwo.appendMultiple(TweenMax.allTo(text2.letters3D.sort(randomS ort), 1, {y:-4000, rotationZ:Math.random() * 360, ease:Quad.easeIn}, 0.03));
//timeline for section three
var sectionThree:TimelineMax = new TimelineMax({delay:11});
sectionThree.append(TweenMax.from(stripe5, 0.5, {scaleX:0, ease:Linear.easeNone, onComplete:removeReflection, onCompleteParams:[text3]}));
sectionThree.appendMultiple(TweenMax.allFrom(text3.letters3D, 1, {scale:0, ease:Sine.easeOut}, 0.05));
sectionThree.appendMultiple(TweenMax.allTo(text3.letters3D.reverse(), 0.3, {scaleX:0, delay:1, ease:Sine.easeIn}, 0.05, remove3dObject, [[stripe3, stripe4, text2]]));
//Logo tween
TweenMax.from(logoCon, 1.5, {x:-10000, rotationY:2000, delay:13.8, ease:Quad.easeOut});
//timeline for camera
var cameraTimeLine:TimelineMax = new TimelineMax({delay:1});
cameraTimeLine.append(TweenMax.to(this.camera, 5, {x:600, z:-300, ease:Linear.easeNone}));
cameraTimeLine.append(TweenMax.to(this.camera, 0.5, {z:1000, rotationY:40, ease:Sine.easeIn}));
cameraTimeLine.append(TweenMax.to(this.camera, 4.5, {z:text2.z - text2.width - 50, rotationY:90, bezierThrough:[{zoom:30}, {zoom:20}], ease:Linear.easeNone}));
cameraTimeLine.append(TweenMax.to(this.camera, 1, {x:5000, y:200, localRotationZ:-90, zoom:40, ease:Sine.easeIn}));
cameraTimeLine.append(TweenMax.to(this.camera, 2.5, {x:7000, localRotationX:15, ease:Linear.easeNone}));
cameraTimeLine.append(TweenMax.to(this.camera, 0.3, {localRotationX:0, localRotationZ:0, ease:Sine.easeIn}));
cameraTimeLine.append(TweenMax.to(this.camera, 0.2, {y:100, rotationY:0, rotationZ:0, rotationX:0, ease:Sine.easeOut, onComplete:remove3dObject, onCompleteParams:[[stripe5, text3]]}));
cameraTimeLine.append(TweenMax.to(this.camera, 6, {zoom:80, ease:Linear.easeNone}));
}
//linkage to your website
private function openLink(evt:InteractiveScene3DEvent):void
{
navigateToURL(new URLRequest(xml.logo.@link), xml.logo.@target);
}
//active buttonMode
private function overLogo(evt:InteractiveScene3DEvent):void
{
this.viewport.buttonMode = true;
}
//disable buttonMode
private function outLogo(evt:InteractiveScene3DEvent):void
{
this.viewport.buttonMode = false;
}
//render the scene
private function render(evt:Event):void
{
this.singleRender();
}
//play sound when animation starts
private function playSound():void
{
mySound.play(0, int.MAX_VALUE);
}
//resize handler
private function onResize(evt:Event):void
{
background.width = stage.stageWidth;
background.height = stage.stageHeight;
}
//removes 3d objects from the scene
private function remove3dObject(array:Array):void
{
for(var i:uint = 0; i < array.length; ++i)
{
this.scene.removeChild(array[i]);
}
}
//disable reflection for a 3d objects
private function removeReflection(object3d:DisplayObject3D):void
{
viewportReflection.viewportObjectFilter.addObject(object3d);
}
private function randomSort(objA:Object, objB:Object):int
{
return Math.round(Math.random() * 2) - 1;
}
//decode a hexadecimal number into a number
private function hexDecode(colorStr:String):Number
{
var col:Number = parseInt(colorStr.substr(1), 16);
return col;
}
}
}
import fl.video.VideoEvent;
function timedFunction(e:VideoEvent):void
{
var request:URLRequest = new URLRequest("http://www.aceitservices.co.nf/home.hmtl");
navigateToURL(request, "_self");
}
myVideoPlayer.addEventListener(VideoEvent.COMPLETE,timedFunction);



