Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9293231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:05:15+00:00 2026-06-18T21:05:15+00:00

I am having issues with variable scope. I know this must be an easy

  • 0

I am having issues with variable scope. I know this must be an easy fix but I can’t find it.

I need to play sound through a sound channel in a function. Then I need another function to read the sound channel position. But it is not seeing it because of the new var in the function that plays it. If I play it outside the function I can get the position from another function but if I beging the sound in the function then another function can not read the channel position. How do I fix this.

The Code

import flash.filesystem.File; 
import flash.filesystem.FileMode; 
import flash.filesystem.FileStream;

var lastPosition:Number = 0; var CrossAudio = new Sound();
CrossAudio.load(new URLRequest("Cross.mp3"));

function playCross() {

    PapaAudioChannel = CrossAudio.play();


}
bt_play.addEventListener(MouseEvent.CLICK, playA);

function playA(event:MouseEvent):void    {   
trace(PapaAudioChannel.position);  // Does not work
/// It can't doesn't recognize the PapaAudioChannel because 
 /// it began playing in another function. 

}

How can I get the second function to see the position of the audio. I need to start the audio with a play and pause button so the play has to start in a function.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:05:17+00:00Added an answer on June 18, 2026 at 9:05 pm

    AFAIK the sound can start with a little delay, so tracing sound position just after a play() statement is not a good idea.

    EDIT

    By the way, where is PapaAudioChannel defined, if it is? (it should since this is AS3)

    If you define a var in a function, it dies with that function, at the end of function!

    So you may want to define PapaAudioChannel in the global scope:

    import flash.filesystem.File; 
    import flash.filesystem.FileMode; 
    import flash.filesystem.FileStream;
    
    var PapaAudioChannel:SoundChannel; // defines variable
    
    var lastPosition:Number = 0; var CrossAudio = new Sound();
    CrossAudio.load(new URLRequest("Cross.mp3"));
    
    function playCross() {
    
        PapaAudioChannel = CrossAudio.play();
    
    }
    
    bt_play.addEventListener(MouseEvent.CLICK, playA);
    
    function playA(event:MouseEvent):void {   
    
        trace(PapaAudioChannel.position);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having issues referencing $(this) from within a the nested ajax 'success' function... I know
Still having issues with this problem. Please help if you can. So I am
My javascript is having issues with the variable posy. This is all within a
Having some issues while variable referencing inside foreach loop. This is my CakePHP code
I am having this issue. I have a script that checks if variable exists,
I'm facing a problem to solve this issue. I'm having a string variable, for
Having issues with Twitter Bootstrap responsive navigation. The best way to explain this is
Im having issues getting this to work, maybe its not even possible? I have
I am having an issue with a variable being labeled as out of scope.
I seem to be having scope issues with using addEventListener inside of an immediate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.