Jump to content

Flash Object using less CPU?


AzKay
 Share

Recommended Posts

For example.

I have a flash, embeded via flash control, in autoit.

But, The flash seems to be taking up around 99% CPU, And this seems to hang any functions called while the flash has high CP usage.

For example, We'll use a hotkey.

$Form1 = GUICtr..etc
$Obj1 = objcreateflashetc..
#/endguiwhatever.
$Obj1.Movie = "http://.swf"
hotkeyset("{F2}", "test")

while 1
wend

func test()
$Obj1.Quality = 4
endfunc

Now, with this example. If the flash is running, And is taking up said memory usage, And I press F2, Nothing will happen until I minimize the window, and reopen the window.

So, it seems, while I have the script running, nothing else will work, unless I minimize/reopen the window, Every time.

The only fix I found to this, Is to give the script, realtime priority. But, That is not what I want, Because, It will usually just hang the computer.

Any ideas?

PS; Without adding a sleep.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Because, My script will be reading from the flash. And if I put a sleep in there, It has a very likely chance of not getting the information.

And, The sleep shouldnt be the problem. Its more of a, Flash using alot of memory, problem.

Which will come to me next question.

Would there be a way to interact with the flash objects, Say, in an IE window?

Ah yes, Smoke, You remember my senseless explanations, Dont you? x3

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

  • Moderators

The sleep shouldnt be the problem.

Your kidding right?

Ah yes, Smoke, You remember my senseless explanations, Dont you? x3

huh?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Your kidding right?

huh?

Ive added a Sleep(1000) in there, And no avail. Doing the same thing as before. While the GUI is up, The script hangs. Whiles its minimized, It continues.

By the senseless posts, I meant.

One of my posts, That Im trying to explain what I want, But it makes no sense to anyone.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

  • Moderators

Ive added a Sleep(1000) in there, And no avail. Doing the same thing as before. While the GUI is up, The script hangs. Whiles its minimized, It continues.

By the senseless posts, I meant.

One of my posts, That Im trying to explain what I want, But it makes no sense to anyone.

Yeah... you said it.

Post a working example (gets tiresome saying over and over to you).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yeah... you said it.

Post a working example (gets tiresome saying over and over to you).

Yeah, Well... You love it. :)

ANYWAYS. I must leave for now. I have to be up early. Ill post when I get back tomorrow. Providing I dont forget, Like I usually do.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

ActionScript 3 allows a much more efficient two-way callback system between ActiveX containers and Flash objects called the ExternalAPI. In attachment you'll find something I've been working on which is based on Flex, but the AS code will work in Flash as well. I'm using the XMLDOM au3 to parse the XML to and from the SWF movie.

Link to comment
Share on other sites

  • 1 month later...

OK attachment didn't work. Check my article on the subject on my blog: http://active6.wordpress.com/

Hey there active6,

Thanks alot for that handy-dandy tutorial. If anybody else has been locking horns with ExternalInterface then I highly recommend it. I learned alot from it but I think something must have got lost in my translation from Flex to Flash. I'm able to send from Flash to Autoit fine, but every time I try to use CallFunction() I get an unspecified error with number #80020009.

Here's my autoit code up to that point:

#include <GUIConstants.au3>
#include <_XMLDomWrapper.au3>

Opt("GUIOnEventMode", 1);event capturing mode
Global $busy = True

$swfFile = "myExtTest2.swf"
$oSwf = ObjCreate("ShockwaveFlash.ShockwaveFlash")

$hModWnd = GUICreate("Flash External API Demo", 400, 450, -1, -1, -1)

$GUIActiveX = GUICtrlCreateObj($oSwf, 0, 0, 400, 400)
$SinkObject = ObjEvent($oSwf, "FLA_") 
$oMyError = ObjEvent("AutoIt.Error", "COMErrFunc")
With $oSwf
    .Movie = @ScriptDir & '\' & $swfFile;
    .ScaleMode = 3; 0 showall, 1 noborder, 2 exactFit, 3 noscale
    .bgcolor = "#999999";
    .Loop = False
    .wmode = "Opaque"; Opaque / transparent
    .allowScriptAccess = "Always"
EndWith

GUISetOnEvent($GUI_EVENT_CLOSE, "closeTest");Set close handler for AI GUI

GUISetState()

;=============THE ERROR COMES FROM THIS LINE======================>>>>>>>>
$oSwf.CallFunction('<invoke name="hideMC"><arguments><string></string></arguments></invoke>')
;===========================================================>>>>>>>>

While $busy
    Sleep(10)
WEnd

Func FLA_FlashCall($xml)
    _XMLLoadXML($xml)
    Local $calledFunc = _XMLGetAttrib(" / invoke", "name")
    $parameters = _XMLGetValue(" / invoke / arguments / string")
    MsgBox(1, "Call from Flash", "Function: " & $calledFunc & @CRLF & "Parameter: " & $parameters[1] & @CRLF & "Full XML:" & $xml)
EndFunc 

Func closeTest();Close GUI Event Handler
    $busy = False
    GUIDelete()
EndFunc  ;==>closeTest

Func COMErrFunc()
    MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    SetError($err); to check for after this function returns
EndFunc  ;==>COMErrFunc

I've tried every combination of xml markup I could think of but I still get the same error. At one point I used clipPut($xml) and pasted it in to make sure I did it right and found that Flash likes to add returntype="xml" to the invoke tag, but it was still a no-go. In your blog you mentioned using Flash 8. Is it possible that something has changed in CS3? The manual isn't much help.

Here's my AS if it helps:

import flash.external. *;
if ( ! ExternalInterface.available){
    trace ("Unable to connect to the container")
}
else{
    function clickListener (eventObj : Object) : Void {
        var actvBtnName : String = eventObj.target.label.toString ();
        ExternalInterface.call (actvBtnName);
    }
    function hideMC () : Void   {
        mc._visible == true ? mc._visible = false : mc._visible = true;
    }
    function flashFunc (str : String) : Void    {
        in_ti.text = "Hello " + str;
    }
    
    ExternalInterface.addCallback ("hideMC", hideMC);
    
    talkBtn.addEventListener ("click", clickListener);
}

Anything jumping out at ya there? Either way, thanks again for the great tute.

Link to comment
Share on other sites

I'm not that experienced with Flash CS3 yet, but yes, there are some differences compared to 8. Probable causes I can think of:

-I believe in CS3 the addcallback syntax is: ExternalInterface.addCallback ("hideMC", null, hideMC);

-I seem to remember having a similar problem calling a function with no parameters, like you do here. I think CS3 also expects the returntype to be specified. Have you tried adding a dummy string as parameter, like this:

<invoke name=""hideMC"" returntype=""xml""><arguments><string>dummy</string></arguments></invoke>

Link to comment
Share on other sites

  • 1 month later...

To answer the original question:

To reduce the cpu usage of swf files, lower the frame rate in the source file. 12 is usually the lowest i would ever go( usually reserved for banner ads for the reason that there will more than likely be more than 1 on the page) and 24 is used for digital video. so something in between is desirable for flash interfaces.

Also using high resolution images scaled down also causes strain on the cpu

Edited by Cr8iveOD
Link to comment
Share on other sites

  • 3 years later...

I think... i will usage... :)

Here... See this.. code... :)

; Reduce memory
ProcessSetPriority(@AutoItExe, 3)
; After done set to normal
ProcessSetPriority(@AutoItExe, 2)

You will let other process to usage resource

so, win willn't saw like hang or crash... :P

Edited by prazetto

# Button. Progressbar - Graphical AutoIt3 Control (UDF) # GTK on AutoIt3 - GTK+ Framework | Widgets

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...