Code: Select all
procedure TMainForm.FlashPlayerControl1LoadExternalResourceEx(
ASender: TObject;
const URL: WideString;
Stream: TStream;
var bHandled: Boolean);
var
ContentProviderThread: TContentProviderThread;
begin
if URL = 'images/embedded_image1.jpg' then
begin
ContentProviderThread := TContentProviderThread.Create(Stream);
bHandled := true;
end;
end;
...
TContentProviderThread = class(TThread)
private
FResourceStream: TStream;
FBuffer: TMemoryStream;
...
end;
...
procedure TContentProviderThread.DoWrite;
var
nWrittenBytes: integer;
begin
nWrittenBytes := FResourceStream.Write(FBuffer.Memory^, FBuffer.Size);
if nWrittenBytes = 0 then
// Write returns 0, if loading was cancelled by some reason
FStop := true;
end;
...
procedure TContentProviderThread.Execute;
begin
while not FStop do
begin
// preparing buffer
PrepareBuffer;
if FBuffer.Size > 0 then
// always call DoWrite using Synchronize!
Synchronize(DoWrite);
end;
// free the stream after providing all amount of data!
FResourceStream.Free;
end;
Code: Select all
type
TSimpleThread = class(TThread)
private
ResourceStream: TStream;
procedure DoWrite;
protected
procedure Execute; override;
public
constructor Create(Stream: TStream);
end;
constructor TSimpleThread.Create(Stream: TStream);
begin
inherited Create(False);
ResourceStream := Stream;
end;
procedure TSimpleThread.DoWrite;
var
x: Integer;
begin
x := 42;
ResourceStream.Write(x, SizeOf(x));
end;
procedure TSimpleThread.Execute;
begin
try
Synchronize(DoWrite);
finally
ResourceStream.Free;
end;
end;
procedure TMainForm.FlashGlobalLoadExternalResourceEx(const URL: WideString; Stream: TStream; out bHandled: Boolean);
begin
TSimpleThread.Create(Stream);
bHandled := True;
end;
... SetGlobalOnLoadExternalResourceHandlerEx(FlashGlobalLoadExternalResourceEx);
...
Code: Select all
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
paddingRight="0"
paddingLeft="0"
paddingTop="0"
paddingBottom="0"
creationComplete="cc()"
>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var d1:ArrayCollection = new ArrayCollection([]);
private function cc():void
{
var loader:URLLoader = new URLLoader;
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, testHandler2);
loader.load(new URLRequest("http://us.i1.yimg.com/us.yimg.com/i/ww/sp/pacg7.gif"));
}
private function testHandler2(e:Event):void
{
//callLater(testHandler, [e]);
testHandler(e);
}
private function testHandler(e:Event):void
{
var loader:URLLoader = URLLoader(e.currentTarget);
loader.data.endian = Endian.LITTLE_ENDIAN;
while (loader.data.bytesAvailable)
d1.addItem(loader.data.readInt());
}
]]>
</mx:Script>
<mx:List width="100%" dataProvider="{d1}"/>
</mx:Application>
Code: Select all
undefined
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
Code: Select all
undefined
at ListCollectionViewCursor/seek()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:2072]
at mx.controls.listClasses::ListBase/seekPositionSafely()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:4035]
at mx.controls.listClasses::ListBase/adjustScrollPosition()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:3739]
at mx.controls.listClasses::ListBase/updateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:3626]
at mx.controls::List/updateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\List.as:1003]
at mx.controls.listClasses::ListBase/validateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:3279]
at mx.managers::LayoutManager/validateDisplayList()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:605]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:678]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8565]
at mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8508]
Code: Select all
procedure TMainForm.FlashGlobalLoadExternalResourceEx(const URL: WideString; Stream: TStream; out bHandled: Boolean);
begin
TSimpleThread.Create(Stream);
bHandled := True;
end;
jpierce wrote:The reason I'm not testing URL is that this is a simple test app.
So do you have a test case you use to test this code? Do you use Flex? Can you replicate my errors?
Thanks.
jpierce wrote:Sent!
andreaarg wrote:Is it possible to catch OnLoadExternalResourceEx AND OnLoadExternalResource for one TFlashPlayerControl, based on some criteria? For example, using OnLoadExternalResource to handle small data requests (such as some text) that are non threaded handled, and using OnLoadExternalResourceEx for data requests that need more processing (such as generating an image thumbnail)
Softanics wrote:andreaarg wrote:Is it possible to catch OnLoadExternalResourceEx AND OnLoadExternalResource for one TFlashPlayerControl, based on some criteria? For example, using OnLoadExternalResource to handle small data requests (such as some text) that are non threaded handled, and using OnLoadExternalResourceEx for data requests that need more processing (such as generating an image thumbnail)
If a handler returns a small piece of data immediately, you can use OnLoadExternalResource. If data is huge, use OnLoadExternalResourceEx.
I hope I understand your question well...
Thank you.
coolshadow wrote:BTW: Have you any idea about the new version?
For example to make the TFlashplayercontrol and Ttransparentflashplayercontrol to be one component ,not two
Return to “Delphi / Builder / VCL Edition”
Users browsing this forum: No registered users and 2 guests