Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

sharedobject - Sound - as3

Explorer ,
Feb 18, 2016 Feb 18, 2016

How it is possible to save a sound-object in Sharedobject !?

var meinsound1:blablameinsound1 = new blablameinsound1();

var meinsound2:blameinsound2 = new blameinsound2();

var sharedO:SharedObject;

sharedO = SharedObject.getLocal("blabla");

var ktoenezufallarray:Array = new Array(meinsound1,meinsound2);

var ahaktoenezufallarray:Array = new Array();

button.addEventListener(MouseEvent.MOUSE_DOWN, buttonf);

function buttonf(event:MouseEvent):void

{

    speicher();

}

if (sharedO.data.kmelodie)

{

    ktext.text=sharedO.data.kmelodie[0].toString();

    ahaktoenezufallarray=sharedO.data.kmelodie;

    ahaktoenezufallarray[0].play(0,1);

    sharedO.data.kmelodie[0].play(0,1);

}

function speicher()

{

    var savingArr:Array = new Array ;

    for (var i:int=0;i<ktoenezufallarray.length;i++)

    {

        savingArr.push(ktoenezufallarray);

    }

    sharedO.data.kmelodie= savingArr;

    sharedO.flush();

    sharedO.data.kmelodie[0].play(0,1);

}

TOPICS
ActionScript
696
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 18, 2016 Feb 18, 2016

you can save (in your sharedobject) the string name of your sound class and then restore the class name using getDefinitionByName:

var meinsound1:blablameinsound1 = new blablameinsound1();

var meinsound2:blameinsound2 = new blameinsound2();

var sharedO:SharedObject;

sharedO = SharedObject.getLocal("blabla");

var ktoenezufallarray:Array = new Array(meinsound1,meinsound2);

var ahaktoenezufallarray:Array = new Array();

button.addEventListener(MouseEvent.MOUSE_DOWN, buttonf);

function buttonf(eve

...
Translate
Community Expert ,
Feb 18, 2016 Feb 18, 2016

you can save (in your sharedobject) the string name of your sound class and then restore the class name using getDefinitionByName:

var meinsound1:blablameinsound1 = new blablameinsound1();

var meinsound2:blameinsound2 = new blameinsound2();

var sharedO:SharedObject;

sharedO = SharedObject.getLocal("blabla");

var ktoenezufallarray:Array = new Array(meinsound1,meinsound2);

var ahaktoenezufallarray:Array = new Array();

button.addEventListener(MouseEvent.MOUSE_DOWN, buttonf);

function buttonf(event:MouseEvent):void

{

    speicher();

}

if (sharedO.data.kmelodie)

{

    ktext.text=sharedO.data.kmelodie[0].toString();

    ahaktoenezufallarray=sharedO.data.kmelodie;

    ahaktoenezufallarray[0].play(0,1);

    sharedO.data.kmelodie[0].play(0,1);

}

function speicher()

{

    var savingArr:Array = new Array ;

    for (var i:int=0;i<ktoenezufallarray.length;i++)

    {

        savingArr.push(getQualifiedClassName(ktoenezufallarray));

    }

    sharedO.data.kmelodie= savingArr;

    sharedO.flush();

    var C:Class=Class(getDefinitionByName(sharedO.data.kmelodie[0]));

var sound:*=new C();

sound.play(0,1);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 19, 2016 Feb 19, 2016

the string name of my sound class i get with .toString() too,

but i have no opportunity to start the sound in this section:


if (sharedO.data.kmelodie)

{

  ...

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2016 Feb 19, 2016

use the code i suggested.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 19, 2016 Feb 19, 2016

sorry, but I don't understand how i use your code in my section:

if (sharedO.data.kmelodie)

{


could u please write an example?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2016 Feb 19, 2016

again, this is the code to play a sound:

    var C:Class=Class(getDefinitionByName(sharedO.data.kmelodie[0]));

var sound:*=new C();

sound.play(0,1);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 19, 2016 Feb 19, 2016

yes, it works - thank you!

i wanna to get the whole array... if it is possible...:

for (var i:int=0;i<2;i++)

    {

    ahaktoenezufallarray.push(getDefinitionByName(sharedO.data.kmelodie));
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2016 Feb 19, 2016

use;

for (var i:int=0;i<2;i++)

    {

   ahaktoenezufallarray.push(Class(getDefinitionByName(sharedO.data.kmelodie)));
}

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2016 Feb 20, 2016

after restart ktext.text shows: [class blablameinsound1]

but why it doesn't worked with "ahaktoenezufallarray[0].play(0,1);" ????

{

       ahaktoenezufallarray.push(Class(getDefinitionByName(sharedO.data.kmelodie)));

}

    //ahaktoenezufallarray[0].play(0,1);

    ktext.text=ahaktoenezufallarray[0];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2016 Feb 21, 2016
LATEST

Ok, sorry it works... sometimes I need a little bit longer...

for (var i:int=0;i<sharedO.data.kmelodie.length;i++)

{
   var C:Class=Class(getDefinitionByName(sharedO.data.kmelodie));
   var sound:*=new C();
   ahaktoenezufallarray.push(sound);

    }

    ahaktoenezufallarray[1].play(0,1);

    ktext.text=ahaktoenezufallarray.toString();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines