[Laszlo-dev] add sprite to canvas
Lucas Lain
lucas.lain at gmail.com
Sun Mar 21 06:08:09 PDT 2010
I can see the red line now! :)
The security error shows up when computeSpectrum is called.
I found this:
"the Error #2121 happens when you try to call the computeSpectrum
function when another flash file with sound is loaded from a different
domain.
For example, if you have youtube open when trying to view a flash file
that uses computeSpectrum, it will fail because youtube did not grant
your domain access to get its sound info....
It appears the only "solution" is to put your computeSpectrum in a
try/catch block (or use areSoundsInaccessable method before calling
computeSpectrum ) and simply notify the user that a flash file in a
different window is interfering with your sound visualizations!"
But I'm not using flash in any window :(
On Sun, Mar 21, 2010 at 9:46 AM, Henry Minsky <henry.minsky at gmail.com> wrote:
> I tried to compile and run your example, as follows, and it ran without
> error for me. It displayed a red line
>
> <canvas>
> <class name="spectrum" extends="view">
> <passthrough>
> import flash.display.Sprite;
> import flash.display.StageAlign;
> import flash.display.StageScaleMode;
> import flash.events.*;
> import flash.media.Sound;
> import flash.media.SoundChannel;
> import flash.media.SoundMixer;
> import flash.media.SoundTransform;
> import flash.net.URLRequest;
> import flash.utils.Timer;
> import flash.geom.Matrix;
> import flash.utils.ByteArray;
> import flash.text.TextField;
> import flash.text.TextFieldAutoSize;
> import flash.text.TextFormat;
> </passthrough>
>
> <attribute name="_ba" value="null"/>
> <attribute name="_gr" value="null"/>
> <method name="init"><![CDATA[
> this._ba = new ByteArray();
> this._gr = new Sprite();
> this._gr.x = 20;
> this._gr.y = 200;
>
> canvas.sprite.addChild(this._gr);
>
> var time:Timer = new Timer(50);
>
> time.addEventListener(TimerEvent.TIMER, timerHandler);
> time.start();
> ]]>
> </method>
>
> <method name="timerHandler" args="e:Event"><![CDATA[
>
> var ba:ByteArray = this._ba;
> var gr:Sprite = this._gr;
>
> SoundMixer.computeSpectrum(ba, true);
> var i:int;
> gr.graphics.clear();
> gr.graphics.lineStyle(0, 0xFF0000);
> gr.graphics.beginFill(0xFF0000);
> gr.graphics.moveTo(0, 0);
> var w:int = 2;
> for (i=0; i<512; i+=w) {
> var t:Number = ba.readFloat();
> var n:Number = (t * 100);
> gr.graphics.drawRect(i, 0, w, -n);
> }
> ]]>
> </method>
> </class>
> <spectrum/>
>
> </canvas>
>
> Do you have the Flash player installed?
> Try running either in backtrace mode or without debugging enabled, and see
> if you can
> get more information about where the errors is coming from. In backtrace
> mode, you can click on the error to inspect it. In non-debug mode, the Flash
> debug player will give you a native Flash backtrace.
>
>
> On Sun, Mar 21, 2010 at 8:38 AM, Lucas Lain <lucas.lain at gmail.com> wrote:
>>
>> Hello Henry,
>>
>> Thank you for your answer. I modified the code and I can compile now.
>>
>> But I can't see the sprite, and I'm getting a runtime error:
>>
>> ERROR @spectrum.lzx≈46: SecurityError: Error #2123
>>
>> Any Ideas? Could you use this class?
>>
>> Best!
>>
>> L.
>>
>>
>> On Sun, Mar 21, 2010 at 1:47 AM, Henry Minsky <henry.minsky at gmail.com>
>> wrote:
>> > Also you will need an extra arg to your handler method
>> >
>> > <method name="timerHandler" args="e:Event">
>> >
>> > Because the contract for a AS3 event listener is that it needs to accept
>> > one
>> > argument.
>> >
>> > "This function must accept an Event object as its only parameter and
>> > must
>> > return nothing"
>> >
>> >
>> >
>> >
>> > On Sat, Mar 20, 2010 at 11:39 PM, Henry Minsky <henry.minsky at gmail.com>
>> > wrote:
>> >>
>> >> To get the sprite, just "canvas.sprite" ought to work, although the
>> >> cross
>> >> platform API to get the sprite is canvas.getDisplayObject()
>> >>
>> >>
>> >>
>> >> On Sat, Mar 20, 2010 at 5:21 PM, Lucas Lain <lucas.lain at gmail.com>
>> >> wrote:
>> >>>
>> >>> Hello everybody,
>> >>>
>> >>> does anyone know how to add a sprite to an openlaszlo canvas or view?
>> >>>
>> >>> I wrote/modified the attached class to visualize the sound spectrum.
>> >>>
>> >>> This line is the one supposed to do the trick:
>> >>>
>> >>> canvas.content.sprite.addChild(this._gr);
>> >>>
>> >>>
>> >>> Best!
>> >>>
>> >>>
>> >>> --
>> >>> Lucas
>> >>
>> >>
>> >>
>> >> --
>> >> Henry Minsky
>> >> Software Architect
>> >> hminsky at laszlosystems.com
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Henry Minsky
>> > Software Architect
>> > hminsky at laszlosystems.com
>> >
>> >
>> >
>>
>>
>>
>> --
>> Lucas
>
>
>
> --
> Henry Minsky
> Software Architect
> hminsky at laszlosystems.com
>
>
>
--
Lucas
More information about the Laszlo-dev
mailing list