how to display remaining time of song in drag mode in AS3 - actionscript-3

I developed an mp3 player in adobe flash. I want something that when dragging seekbar, time display remains live, like jetaudio windows.
my problem is in line 8
this is my code:
function onloops(event:Event):void {
Object(this).slider_mc.trailer_mc.width=Object(this).slider_mc.knob_mc.x+Object(this).slider_mc.knob_mc.width/2;
if (soundChannel!=null) {
pos=soundChannel.position;
pos3=sound.length-soundChannel.position;
}
if (readyToPlay) {
pos=sound.length*Object(this).slider_mc.knob_mc.x/400;
pos3=(Object(this).slider_mc.knob_mc.x/400)*sound.length;
}
if (dragging==true&&soundChannel!=null) {
pos=sound.length*Object(this).slider_mc.knob_mc.x/400;
pos3=slider_mc.knob_mc.x/400;
} else if (soundChannel!=null&&dragging!=true&&readyToPlay==true&&isplaying) {
pos1=Math.round(soundChannel.position/1000);
pos2=Math.round(sound.length/1000);
this.slider_mc.knob_mc.x=Math.round(soundChannel.position/sound.length*400);
}
var minutes:Number=Math.floor(pos/1000/60);
var seconds:Number=Math.floor(pos/1000)%60;
Object(this).elapsed_totaltime_txt.text=minutes+":"+seconds
var remainminutes:Number=Math.floor(pos3/1000/60);
var remainseconds:Number=Math.floor(pos3/1000);
remainminutes=remainminutes%60;
remainseconds=remainseconds%60;
Object(this).remainigtime_txt.text="-"+remainminutes+":"+remainseconds
}

Related

my button keep displaying the same frame in adobe flash action script 3.0

I have been doing this for a week and i cannot get it right. Im still new with adobe flash and currently doing assignment on BMI calculator.
but my button keep directing me to the 'obese' frame eventho the result should be underweight. there's no error reported by the compiler.
this is my coding.
stop();
*btn_calculate.addEventListener(MouseEvent.CLICK, countbmi);*
*function countbmi(e:MouseEvent):void*
{
var num1=Number(weight.text);
var num2=Number(heightm.text);
var num3:Number= num1/(num2*num2);
if (num3<=18.5)
{
gotoAndPlay(7);
}
if (num3>18.5 && num3<=24.9)
{
gotoAndPlay(8);
}
if (num3>25 && num3<29.9)
{
gotoAndPlay(9);
}
else
{
gotoAndPlay(10);
}
}

Alternative array navigation hack in AS3 not running as defined :(

for some reasons, this code does not want to work; its supposed to be a convenient alternative to using "arrays" for navigation buttons whereby the clicking of one button removes the click state from the rest -
nav_mc.buttonMode=true;
nav_mc.addEventListener(MouseEvent.MOUSE_OVER, navOver);
nav_mc.addEventListener(MouseEvent.MOUSE_OUT, navOut);
nav_mc.addEventListener(MouseEvent.CLICK, navClick);
nav_mc.nav1_mc.mouseChildren=false;
nav_mc.nav2_mc.mouseChildren=false;
nav_mc.nav3_mc.mouseChildren=false;
nav_mc.nav4_mc.mouseChildren=false;
var currentNav:MovieClip;
function navOver(e:MouseEvent):void {
var navItem:MovieClip=e.target as MovieClip;
trace(navItem.name);
if (navItem!=currentNav) {
navItem.gotoAndStop(2);
}
}
function navOut(e:MouseEvent):void {
var navItem:MovieClip=e.target as MovieClip;
if (navItem!=currentNav) {
navItem.gotoAndStop(1);
}
}
function navClick(e:MouseEvent):void {
var navItem:MovieClip=e.target as MovieClip;
if (currentNav!=null) {
navItem.gotoAndStop(1);
}
currentNav=navItem;
navItem.gotoAndStop(3);
}
please, been on this for hours now, what am I missing out?
My guess is: you should change the navItem variable to the currentNav, inside of the if block here:
if (currentNav!=null) {
navItem.gotoAndStop(1);
}
It looks like you want to make some changes to the current active item (currentNav).
UPD.: My advice is: try to change the code above to the next code
if (currentNav!=null) {
currentNav.gotoAndStop(1);
}
UPD 18-11-2015, Toggle buttons:
It's hard to say if my code works or not (I don't have the whole project to test it), but it looks like it should.
function navClick(e:MouseEvent):void
{
var navItem:MovieClip=e.target as MovieClip;
if (currentNav != null)
{
currentNav.gotoAndStop(1);
}
if(currentNav == navItem)
{
currentNav = null;
}else
{
currentNav = navItem;
navItem.gotoAndStop(3);
}
}

Canvas on Chrome Mobile not working after rotation

Trying to fix a really annoying problem that I'm having. I have an HTML5 canvas that I'm allowing users to draw on, which is loaded in an iframe. When the page first loads, it checks to see if we're on a mobile device and, if so, it resizes the whole page, including the iframe. I then have a setTimeout that runs every few seconds to check and see if my canvas is a different size from the frame it's loaded in. If it's different, I change the canvas size and then reinitialize it (using Kineticjs 1.0, I know there are newer versions but we're not ready to upgrade).
This works in most of the mobile browsers that we test, but Chrome (on iOS and Android) doesn't allow drawing on the canvas either when the page is first loaded in portrait or after an orientation change. It just scrolls the page (standard touch event) and ignores all of my preventDefaults. I can't even get it to do an alert on touchstart after the orientation changes.
Has anyone run across this before? I'm thinking it's either something with the fact that the canvas itself is changing or that maybe once the new stage(canvas) is created in Kinetic all of the defined listeners become ignored.
Update:
Here's some of the code I'm dealing with:
// This page is loaded in a frame, so we check to see when the parent is loaded
parent.$(document).ready(function()
{
$(document).ready(function()
{
ut();
setTimeout('start_orientation_detect_timer()','2000');
});
});
function start_orientation_detect_timer()
{
if(document.getElementById("data").value.length == 0 && Math.floor(canvas.width) != Math.floor(parent.$(parent.top_origin.frame_array['sig_block_frame']).width()) || Math.floor(canvas.height) != Math.floor(parent.$(parent.top_origin.frame_array['sig_block_frame']).height()))
{
if(top_origin.misc_variables.mobile_device !== false && top.window.orientation == 0)
{
parent.$('#flip_to_landscape_msg').show();
parent.$('#flip_to_landscape_msg').effect("pulsate", { times:200 }, 2000);
}
else
{
parent.$('#flip_to_landscape_msg').stop(true, true);
parent.$('#flip_to_landscape_msg').hide();
}
ut();
}
else
{
// so from this frame several deep, we need to know the orientation, which will only be in the top of the DOM
if(document.getElementById("data").value.length == 0 && top_origin.misc_variables.mobile_device !== false && top.window.orientation == 0)
{
parent.$('#flip_to_landscape_msg').show();
parent.$('#flip_to_landscape_msg').effect("pulsate", { times:200 }, 2000);
}
else
{
parent.$('#flip_to_landscape_msg').stop(true, true);
parent.$('#flip_to_landscape_msg').hide();
}
}
setTimeout('start_orientation_detect_timer()','2000');
}
function ut()
{
canvas=document.getElementById("drawing_canvas");
context = canvas.getContext("2d");
//console.log(Math.floor(parent.$(parent.top_origin.frame_array['sig_block_frame']).width())+' '+Math.floor(canvas.width)+' '+Math.floor(parent.$(parent.top_origin.frame_array['sig_block_frame']).height())+' '+Math.floor(canvas.height));
canvas.width = parent.$(parent.top_origin.frame_array['sig_block_frame']).width();
document.getElementById('saved_layer').style.width = canvas.width;
canvas.height = parent.$(parent.top_origin.frame_array['sig_block_frame']).height();
document.getElementById('saved_layer').style.height = canvas.height;
myStage = new Kinetic.Stage(canvas);
canvas.onmousemove = function()
{
var mousePos = myStage.getMousePos();
var mouseDown = myStage.getMouseDown();
if (mousePos!=null && mouseDown)
{
draw_b(mousePos.x, mousePos.y);
}
else
{
new_segment = true;
}
};
canvas.ontouchstart = function()
{
BlockMove(event);
}
canvas.ontouchmove = function()
{
var mousePos = myStage.getMousePos();
console.log(mousePos);
if (mousePos!=null)
{
draw_b(mousePos.x, mousePos.y);
}
};
canvas.ontouchend = function()
{
new_segment = true;
};
myStage.listen();
}
function BlockMove(event)
{
// Tell Safari not to move the window.
event.preventDefault() ;
}
I know some of this isn't the most updated code, but it does work except for on Chrome mobile. I've gotten it to the point where if I do not call the start_orientation_detect_timer then the canvas is only about 100px wide by 210 tall, but I can draw on it in Chrome mobile. It seems that once the canvas is stretched, I can't draw anymore. Not even a larger canvas with bigger strokes, nothing happens and the touchstart isn't triggered.

how to remove a gallery call when i click in any other button in AS3.0?

so i have this photo gallery with 2 external classes, this code is the timeline code that calls the classes in to import the gallery and make it work.
So far so good, the problem starts when i want to put this photo gallery in a media presentation or website or something with more than 1 layer, it happens that the gallery stays there after being called and increases more gallery's every time i return to that frame with the code.
So i was wondering if its possible create some simple code to add to this one thats says to remove the gallery if im not on frame number 13 or stop calling the classes if im not on that specific frame, something like that.
I tried the "removeChild", it solved half of the problem, it didnt quite removed the gallery but at least stoped the increasing effect.
All i need is a way to remove the gallery when i go to another frame/page.
Can someone help me?
import flashfold.as3.*;
var imgLoader:ImageLoader;
var thumbsToLoad:Array=[];
var menuColumnItems:int=6;
var menuTotItems:int=30;
var menuThumbs:Vector.<Bitmap>=new Vector.<Bitmap>();
var menuBigPics:Vector.<String>=new Vector.<String>();
var menu:SpinnerMenu;
btnSpin.visible=false;
errorBox.wordWrap=true;
errorBox.visible=true;
errorBox.text="Loading thumbnails...";
populatePics();
prepImgs(thumbsToLoad);
function prepImgs(a:Array):void {
imgLoader=new ImageLoader();
imgLoader.addEventListener(ImageLoader.LOAD_ERROR,errorLoading);
imgLoader.addEventListener(ImageLoader.IMGS_LOADED,allLoaded);
imgLoader.loadImgs(a);
}
function errorLoading(e:Event):void {
errorBox.visible=true;
errorBox.text="There has been an error loading images. The server may be busy.";
}
function allLoaded(e:Event):void {
errorBox.visible=false;
initApp();
}
function initApp():void {
var i:int;
for (i=0; i<menuTotItems; i++) {
menuThumbs[i]=imgLoader.bitmapsArray[i];
}
menu=new SpinnerMenu(menuThumbs,menuBigPics,menuColumnItems);
this.addChild(menu);
trace("oi");
menu.x=72;
menu.y=50;
menu.menuInfoBox.x=160;
menu.menuInfoBox.y=90;
this.transform.perspectiveProjection.fieldOfView=70;
this.transform.perspectiveProjection.projectionCenter=new
Point(menu.x+menu.menuWidth/2,menu.y+menu.menuHeight/2);
btnSpin.visible=true;
//We load the initial image.
menu.loadInitial();
}
function populatePics():void {
var i:int;
for (i=1; i<=menuTotItems; i++) {
thumbsToLoad[i-1]="small"+String(i)+".jpg";
}
for (i=1; i<=menuTotItems; i++) {
menuBigPics[i-1]="pic"+String(i)+".jpg";
trace('ok');
btnSpin.addEventListener(MouseEvent.CLICK, spinMenu);
function spinMenu(e:MouseEvent):void {
var r:Number=Math.random();
if (r<0.5) {
menu.doSpin("right");
} else {
menu.doSpin("left");
}
}
}
}
if imgLoader is the gallery that you want deleted then this should help:
if (objectParent.getChildByName("imgLoader") != null) {
trace("imgLoader exsits");
objectParent.removeChild("imgLoader");
}
Basically this is checking if imgLoader exist and if it does, it removes it.

AS3 How to wait for child component to load?

I have a movieclip, we can call it "mc". On my "mc" is a textarea component called "childta". I am creating instances of "mc" with stage.addchild. All is well and going good but when I add a line of code after that to set the text of "childta" it doesnt show up due to the code being executed prior to it being loaded.
I do know I have the code right because if i click the button to set the text of "childta" it does work. So how can I wait for mc.childta to be loaded?
var mcPM:PMBox = new PMBox();
pmwaiting = 1;
mcPM.name = sendername;
stage.addChild(mcPM);
mcPM.x = 200;
mcPM.y = 200;
mcPM.addEventListener(Event.ADDED_TO_STAGE, pmloaded);
}
while(pmwaiting == 1) {
}
MovieClip(stage.getChildByName(sendername)).pmsa.addText(dArray[3]);
mcPM.removeEventListener(Event.ADDED_TO_STAGE, pmloaded);
}
} else {
//Its chat text, add to window
sa.addText(e.data);
}
}
function pmloaded(Event):void {
pmwaiting = 0;
}
Try listening for "ADDED_TO_STAGE"
childta = new TextArea();
childta.addEventListener(Event.ADDED_TO_STAGE,childtaLoaded);
function childtaLoaded(e:Event):void {
//ready to work with
}
addChild(childta);