The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
Please vote in the Forum Structure Poll. Polling will close at 2PM EST on January 21, 2025.

Ultra basic Adobe Flex 3 help

JasconiusJasconius sword criminalmad onlineRegistered User regular
edited May 2008 in Help / Advice Forum
I very much have my Flex training wheels on still, but this one is just weird and I am missing something apparently completely obvious.

This simple script:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	
	<mx:Script>
		<![CDATA[
			
			import flash.media.*;
			
			private var mixer:SoundMixer = new SoundMixer();
			
			mixer = null;
			
		]]>
	</mx:Script>
	
</mx:Application>

For some reason generates an error, saying that mixer is an undefined property. I tried changing private to public and removing it all together, zero difference.

If I do a this. then mixer will show up as a property but you can't access variables in that way in an MXML application.

This is the first time I've ever used anything outside of primitive data types so I'm not sure why it doesn't like this... the code is practically cut and paste from Adobe's documentation.

this is a discord of mostly PA people interested in fighting games: https://discord.gg/DZWa97d5rz

we also talk about other random shit and clown upon each other
Jasconius on

Posts

  • HerschelHerschel Registered User regular
    edited May 2008
    When you put script data in an application like that, what Flex actually does is generate a class that looks something like:
    class MyApp extends Application
    {
    ...
      import flash.media.*;
      private var mixer:SoundMixer = SoundMixer();
      mixer = null;
    ...
    }
    

    Strangely enough, ActionScript lets you run code at the global class level like this. But at that level, it's not associated with any specific instance, and can only see static properties of the class. (Try putting private static var mixer, and you'll see it works.)

    What you really want to do is put the code inside a method that gets called on initialization, by the constructor or by the initialize event:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
           
            <mx:Script>
                    <![CDATA[
                           
                            import flash.media.*;
                           
                            private var mixer:SoundMixer = new SoundMixer();
                           
                           public function init():void
                           {
                           	 mixer = null;
                           }
                    ]]>
            </mx:Script>
           
    </mx:Application>
    

    Also, I think the SoundMixer class has only static methods, so there's no need to instantiate it. You can just do, e.g. SoundMixer.computeSpectrum() :)

    good luck!

    Herschel on
Sign In or Register to comment.