Tengo una web con el código AS3 en un archivo externo. Es como una rueda de imágenes que se van moviendo. El caso es que quiero que, al hacer click en una de ellas, se reproduzca un sonido pero no tengo ni idea de AS3. Creo que el código lo tendría que añadir por aquí (hay mucho código) pero sinceramente no tengo ni idea. Este es el código (perdón de antemano por algo tan largo:
Código :
//______________________________________________Thumbnail Roll Over, Roll Out, Press
//Thumb roll over
private function RollOver(e:Event):void
{
var p:Cube = pContainer[e.target];
var ob:Object = { x:p.extra.tPos.x,
z:p.extra.tPos.z,
time: mtime2,
transition:Img_easeType,
onUpdate: updatePos,
onUpdateParams: [p]
}
Tweener.addTween(p.extra.cPos, ob );
var index = p.extra.index;
// Tween Caption:Fade In/Fade Out
var FadeIn:Function = function(index:Number):void
{
cap.text = capt[index];
Tweener.addTween(cap, {alpha:1, time: (cTime/2), transition:cTrans});
}
Tweener.addTween(cap, {alpha:0, time: (cTime/2) , transition:cTrans, onComplete: FadeIn, onCompleteParams:[index]});
}
// Thumb roll out
private function RollOut(e:Event):void
{
var p:Cube = pContainer[e.target];
var ob:Object = { x:p.extra.oPos.x,
z:p.extra.oPos.z,
time: mtime2,
transition:Img_easeType,
onUpdate: updatePos,
onUpdateParams: [p]
}
Tweener.addTween(p.extra.cPos, ob );
}
// Thumb pressed
private function Press(e:Event):void
{
var container = e.target;
var p = pContainer[container];
if (flag == 0)
{
//Prevent roll over, roll out tween
container.removeEventListener(MouseEvent.ROLL_OVER, RollOver);
container.removeEventListener(MouseEvent.ROLL_OUT, RollOut);
cap.alpha = 1;
des.visible = true;
rs = 0;
pitch = 0;
for (var i:uint = 0; i < numphot; i++)
{
if ( i != p.extra.index)
{
var pl = scene.getChildByName("plane"+i);
pl.container.removeEventListener(MouseEvent.ROLL_OVER, RollOver);
pl.container.removeEventListener(MouseEvent.ROLL_OUT, RollOut);
pl.container.removeEventListener(MouseEvent.MOUSE_DOWN, Press);
pl.container.buttonMode = false;
//_____________________________________________________________________
//Add tweening alpha - Optional
Tweener.addTween(pl.container, {alpha:0, time:2, transition:"easeOutQuint"});
Tweener.addTween(pl.extra.ref.container, {alpha:0, time:2, transition:"easeOutQuint"});
//______________________________________________________________________
//Add tweening scale - Optional
/*
Tweener.addTween(pl.container, {scaleX:0, scaleY:0, time:2, transition:"easeOutQuint"});
Tweener.addTween(pl.extra.ref.container, {scaleX:0, scaleY:0, time:2, transition:"easeOutQuint"});
*/
}
}
var tob:DisplayObject3D = new DisplayObject3D();
tob.x = delta1 * (1 - camera.x) + camera.x;
tob.z = delta1 * (-camera.z) + camera.z;
tob.rotationY = (-angle % 360) + 270;
tob.moveLeft(delta2);
tPos.x = tob.x;
tPos.z = tob.z;
tPos.rotationY = tob.rotationY;
var myob:Object = { x:tPos.x,
z:tPos.z,
y:0,
rotationY:tPos.rotationY,
time:mtime3,
transition:Img_easeType2,
onUpdate:updatePos2,
onUpdateParams: [p]
};
// Move thumbnail to target position
Tweener.addTween( p, myob);
// Move Camera
Tweener.addTween(camera, {y:0, time: dTime, transition:dTrans });
//Fade In Description
des.text = desc[p.extra.index];
Tweener.addTween(des, {alpha:1, time: dTime, transition:dTrans, onComplete:AddEvent, onCompleteParams:[p]});
cID = p.extra.index;
}
else
{
rs = rotatespeed;
pitch = Pitch;
// Plane smooth == false ~ increase performance
p.getMaterialByName("front").smooth = false;
container.removeEventListener(MouseEvent.ROLL_OVER, RollOver2);
container.removeEventListener(MouseEvent.ROLL_OUT, RollOut2);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
var myob2:Object = {x:p.extra.oPos.x,
z:p.extra.oPos.z,
y:0,
rotationY:p.extra.rotationY,
time:mtime3,
transition:Img_easeType2,
onUpdate:updatePos2,
onUpdateParams: [p],
onComplete: RestoreEvent,
onCompleteParams: [p]};
// Move thumbnail back
Tweener.addTween( p, myob2);
for (var j:uint = 0; j < numphot; j++)
{
if ( j != p.extra.index)
{
var pl2 = scene.getChildByName("plane"+j);
pl2.container.addEventListener(MouseEvent.ROLL_OVER, RollOver);
pl2.container.addEventListener(MouseEvent.ROLL_OUT, RollOut);
pl2.container.addEventListener(MouseEvent.MOUSE_DOWN, Press);
pl2.container.buttonMode = true;
//______________________________________________________________
//Add tweening alpha - Optional
Tweener.addTween(pl2.container, {alpha:1, time:2, transition:"easeOutQuint"});
Tweener.addTween(pl2.extra.ref.container, {alpha:1, time:2, transition:"easeOutQuint"});
//______________________________________________________________
//Add tweening scale - Optional
/*
Tweener.addTween(pl2.container, {scaleX:1, scaleY:1, time:2, transition:"easeOutQuint"});
Tweener.addTween(pl2.extra.ref.container, {scaleX:1, scaleY:1, time:2, transition:"easeOutQuint"});
*/
}
}
// Move Camera Back
Tweener.addTween(camera, {y:camHeight, time: dTime, transition:dTrans });
//Fade Out Description
Tweener.addTween(des, {alpha:0, time: dTime, transition:dTrans, onComplete:function():void {des.visible = false}});
//Fade Out image
neededScale = true;
Tweener.addTween(ImgContainer[cID], {scaleX:0, scaleY:0, alpha:0, time:1, transition:"easeOutQuint" });
}
flag = Math.abs(flag-1);
}
//______________________________________________________________________
// New roll over, roll out when a thumbnail is presed
private function AddEvent(p:Cube):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
p.container.addEventListener(MouseEvent.ROLL_OVER, RollOver2);
p.container.addEventListener(MouseEvent.ROLL_OUT, RollOut2);
//Plane smooth == true ~ increase quality
p.getMaterialByName("front").smooth = true;
}
private function RollOver2(e:Event):void
{
if (neededScale)
{
Tweener.addTween(ImgContainer[cID], {scaleX:1, scaleY:1, alpha:0.85, time:1, transition:"easeOutBack" });
neededScale = false;
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
}
private function RollOut2(e:Event):void
{
neededScale = true;
Tweener.addTween(ImgContainer[cID], {scaleX:0, scaleY:0, alpha:0, time:1, transition:"easeOutQuint" });
stage.removeEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
}
private function MouseMove(e:Event):void
{
ImgContainer[cID].x = (stage.mouseX + 10) ;
ImgContainer[cID].y = (stage.mouseY + 10);
}
//_______________________________________________________________Update position
private function updatePos(p:Cube):void
{
p.x = p.extra.cPos.x;
p.z = p.extra.cPos.z;
p.extra.ref.x = p.x;
p.extra.ref.z = p.z;
}
private function updatePos2(p:Cube):void
{
p.extra.cPos.x = p.x;
p.extra.cPos.z = p.z;
p.extra.ref.x = p.x;
p.extra.ref.z = p.z;
p.extra.ref.rotationY = p.rotationY;
}
private function RestoreEvent(p:Cube):void
{
var container:Sprite = p.container;
//Restore Roll Over, Roll Out
container.addEventListener(MouseEvent.ROLL_OVER, RollOver);
container.addEventListener(MouseEvent.ROLL_OUT, RollOut);
}
//________________________________________________________________________
private function MoveCamera(k:Number):void
{
camPos.angle = k * anglePer;
Tweener.addTween(COB, {angle: camPos.angle, time: mtime, transition:Cam_easeType, onUpdate:updateCamera});
}
private function updateCamera():void
{
var x = Math.cos( COB.angle) * cradius;
var z = Math.sin( COB.angle) * cradius;
camera.x = x;
camera.z = z;
angle = COB.angle * 180/Math.PI;
}
private function update3D(e:Event):void
{
if (autorotate)
{
var del = (stage.mouseX - stage.stageWidth * 0.5) * rs;
//var del2 = (stage.stageHeight * 0.5 - stage.mouseY) * pitch;
angle += del;
var x = Math.cos(angle*Math.PI/180)*cradius;
var z = Math.sin(angle*Math.PI/180)*cradius;
camera.x = x;
camera.z = z;
}
scene.renderCamera( camera );
}
private function rePosition(e:Event):void
{
container.x = stage.stageWidth * 0.5;
container.y = stage.stageHeight * 0.5;
// Reposition caption, description
cap.x = (stage.stageWidth - cap.width) * 0.5 ;
cap.y = container.y + 150;
des.x = container.x + 40;
des.y = (stage.stageHeight - des.height) * 0.5 + 20 ;
}
//__________________________________________Apply styleSheet in description field
private function InitDescription():void
{
// load external css
var req:URLRequest = new URLRequest("css/styles.css");
var loader:URLLoader = new URLLoader();
loader.load(req);
loader.addEventListener(Event.COMPLETE, cssLoaded);
// Adding text link event
addEventListener(TextEvent.LINK, clickText);
}
private function cssLoaded(e:Event):void
{
css.parseCSS(e.target.data);
des.styleSheet = css;
}
private function clickText(li:TextEvent):void
{
var myURL:URLRequest = new URLRequest(li.text);
navigateToURL(myURL,"_blank");
}
//___________________________________for Preview only
private function Setup_link():void
{
gal2.buttonMode = gal3.buttonMode = gal4.buttonMode = true;
gal2.addEventListener(MouseEvent.MOUSE_DOWN, go2);
gal3.addEventListener(MouseEvent.MOUSE_DOWN, go3);
gal4.addEventListener(MouseEvent.MOUSE_DOWN, go4);
}
private function go2(e:Event):void
{
var myURL:URLRequest = new URLRequest("./3d2.html");
navigateToURL(myURL,"_self");
}
private function go3(e:Event):void
{
var myURL:URLRequest = new URLRequest("./3d3.html");
navigateToURL(myURL,"_self");
}
private function go4(e:Event):void
{
var myURL:URLRequest = new URLRequest("./3d4.html");
navigateToURL(myURL,"_self");
}
}
}Estoy un poco perdido. Sé que no tiene que ser difícil pero... Gracias de antemano,
Roger.
